1

I'm using the MEAN stack to write a web app for an existing project. The project has several MongoDB collections including one that looks like this:

{ "_id" : ObjectId("553a75a7e4b092e5edad4bce"), 
  "currentMessage" : "Processed.Metadata.To.MetadataDB", 
  "nameSpace" : "test_bulk", 
  "headers" : [
    { "outputFile" : "/projects/databridge/databridge-test/DataBridge/netFiles/" },
    { "className" : "org.renci.databridge.contrib.similarity.ncat.Overlap" }
  ]
}

I'm not having any trouble in mongoose retrieving the top level fields such as currentMessage and nameSpace, but I don't seem to be able to retrieve the headers properly. The headers are essentially a set of name value pairs. Here's my schema def (and I've tried a fair number of others):

var headerSchema = new Schema({
    key:{
        type: String,
        default: '',
        trim: true,
        unique : false,
        // make this a required field
        required: 'key cannot be blank',
    },
    value:{
        type: String,
        default: '',
        trim: true,
        unique : false,
        // make this a required field
        required: 'value cannot be blank',
    }
});

/**
 * DbAction Schema
 */
var DbActionSchema = new Schema({
    // Agent model fields
    currentMessage: {
        type: String,
        default: '',
        trim: true,
        unique : false,
        // make this a required field
        required: 'currentMessage cannot be blank',
    },

    nameSpace: {
        type: String,
        default: '',
        trim: true,
        unique : false,
        // make this a required field
        required: 'nameSpace cannot be blank',
    },

    headers: {
        type: [headerSchema],
    }
});

but I can't get what I want, which is the individual fields of each header as name, value pairs. Any ideas?

JohnnyHK
  • 305,182
  • 66
  • 621
  • 471
  • If you want to support arbitrary header fields, then the schema you've defined is a good choice. But your doc would need to match it as `headers: [{key: 'outputFile', value: '/projects/databridge/databridge-test/DataBridge/netFiles/'}, ...]` – JohnnyHK Sep 14 '15 at 18:04
  • Yeah, I was afraid of that. It's not really what I want because the set of headers is not the same for every entry in the collection. I may have to change my collection so that every header looks something like {"key" : key, "value" : value} Thanks for the response. – HowardLander Sep 14 '15 at 18:24

0 Answers0