【问题标题】:mongoose - query on a field that exists inside of another fieldmongoose - 查询存在于另一个字段中的字段
【发布时间】:2018-02-14 22:25:09
【问题描述】:

我在猫鼬中有这个架构:

 var AnswerSchema = new Schema({
    name : {type : String,required: true},
    study : {type: Schema.Types.ObjectId,ref: 'Study'},
    model : {type: Schema.Types.ObjectId,ref: 'Model'},
    entity : {type : String, required : true},
    opened : {type: Boolean, default : true},
    steps : [{
        step : {_id: {type : String}, name: {type : String}, color: {type : String}, fields: {}},
        tasks : [{
            task:{_id: {type : String}, name: {type : String}, parent: {type : String}, prefix : {type : String , unique : true}},
            progress : {type: Number , min: 0, max: 100, default : 0},
            attachments:[],
            comments:[],
            fields:{},
            predecessors:[],
        }],
        cloned: {type: Boolean, default : false}
    }],
    lastReview : {
        date:{type: String},
        completed : [],
        statusUpdated : [],
        dueDateUpdated : []
    },
    content: {},
    creationDate : {type: Date,default: Date.now},
    lastUpdateDate : Date,
    createdBy : {type: Schema.Types.ObjectId,ref: 'User'},
    lastUpdatedBy : {type: Schema.Types.ObjectId,ref: 'User'}
});

我想做的是查询steps>tasks>task>_id字段来得到匹配某个id x的答案,我该怎么做?

【问题讨论】:

    标签: node.js mongodb mongoose


    【解决方案1】:

    Mongo 会自动搜索你的数组:

    {"steps.tasks.task._id": 你的id}

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-14
      • 1970-01-01
      • 2019-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-03
      • 2016-01-26
      相关资源
      最近更新 更多