Py学习  »  MongoDB

包含子字段Mongodb的多文件Mongoose查询文档[副本]

J. Davidson • 4 年前 • 844 次点击  

嗨,我在mongodb中有以下文档模型

架构是

const ProductionsSchema=new Schema({
        name: {type: String, required: true, unique: true},
        isActive: {type: Boolean, default: true},
        locations: [{
            name: {type: String},
            isActive : {type: Boolean, default: false}
        }],
        trackno: {type: String}
})
Productions:[{ 
       _id: 125,
        name: 'John Smith',
        locations: [{ name: 'Boston', isActive: true}]
        isActive: true,
        trackno: 2123
    }, 
        { 
       _id: 126,
        name: 'Moe Adam',
        locations: [{ name: 'Chicago', isActive: true}]
        isActive: true,
        trackno: 5663
    }, 
     { 
       _id: 126,
        name: 'Henry Noel',
        locations: [{ name: 'Houston', isActive: false}]
        isActive: true,
        trackno: 4552
    }, 
      { 
       _id: 128,
        name: 'Tim Johnson',
        locations: [{ name: 'Denver', isActive: true}]
        isActive: false,
        trackno: 6672
    }

]

我想找出两个都是真的

Productions.find({"isActive" : true , "locations.isActive": true}, (err, list)=>{
      if(err){
            callback(err);
            }
            callback(null, list)
        })

我正在尝试编写查询,因此两个isActive都是真的。在上面的示例数据中,只有前两条记录应该在答案中。但我不断地得到所有的记录,即使是有“错误”的记录,我甚至试过$elemMatch的位置。isActive仍然没有工作。 请告诉我如何修复此问题,以便我只得到只包含两个isActive的真实值的结果。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/51256
 
844 次点击  
文章 [ 1 ]  |  最新文章 4 年前