这是我的模式
petShop: {
name: String,
pets: {
dogs: [{
color: String
name: String
DOB: Date
}],
cats: [{
color: String
name: String
DOB: Date
}],
...
},
...
}比方说,我想找到所有的petShops,有一只white狗,它一定是最年长的狗
例如:
A_petShop只有一条black狗和一条white狗
white狗比black狗老
B_petShop只有一条black狗和一条white狗
black狗比white狗老
C_petShop只有一只black狗和两只white狗
white的一只狗比另外两只狗要老
因此,A_petShop和C_petShop应该是查询结果。
mongoDB命令或猫鼬JavaScript应该是什么样的呢?
发布于 2014-11-07 16:38:22
由于dogs数组首先使用最老的数组进行排序,所以可以通过数字数组索引进行查询:
PetShop.find({'pets.dogs.0.color': 'white'}, function(err, petShops) {...});https://stackoverflow.com/questions/26805653
复制相似问题