Mongoose检索键值对

时间:2015-09-14 17:34:44

标签: mongodb mongoose mean

我使用MEAN堆栈为现有项目编写Web应用程序。该项目有几个MongoDB集合,包括一个如下所示:

{ "_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" }
  ]
}

我在mongoose检索顶级字段(例如currentMessage和nameSpace)时没有遇到任何麻烦,但我似乎无法正确检索标题。标头本质上是一组名称值对。这是我的架构def(并且我已尝试过相当多的其他架构):

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],
    }
});

但是我无法得到我想要的东西,每个标题的各个字段都是名称,值对。有什么想法吗?

0 个答案:

没有答案