我有这个结构
{
"_id" : "EbtLm2Nmb79WWryEr",
"notificationByUsers" : {
"all" : [
{
"account_id" : "X5PjY66JAwgoxDb4L",
"date" : ISODate("2016-07-27T13:48:17.154Z"),
"value" : null
},
{
"account_id" : "2C2FKXaKtmeRMNT3E",
"date" : ISODate("2016-07-27T13:53:10.296Z"),
"value" : "Instant"
},
{
"account_id" : "6Np35oj63cavF4RHs",
"date" : ISODate("2016-07-28T07:18:22.696Z"),
"value" : "Instant"
}
]
}
}
我正在查询
db.Collection.findOne({_id: EbtLm2Nmb79WWryEr, 'notificationByUsers.all':{$elemMatch:{account_id: "2C2FKXaKtmeRMNT3E"}}}, {_id:0, 'notificationByUsers.all.$': 1})
它在roboMongo中返回
{
"notificationByUsers" : {
"all" : [
{
"account_id" : "2C2FKXaKtmeRMNT3E",
"date" : ISODate("2016-07-27T13:53:10.296Z"),
"value" : "Instant"
}
]
}
但在Meteor中,它会使用此查询返回所有数组元素。我想要特定数组元素的结果在robomongo中工作。
答案 0 :(得分:1)
您可以使用字段投影来完成此操作,例如:
MyCollection.findOne({},{ fields : {_id:0, 'notificationByUsers.all':1}});
这将返回如下对象:
{
"notificationByUsers" : {
"all" : [
{
"account_id" : "2C2FKXaKtmeRMNT3E",
"date" : ISODate("2016-07-27T13:53:10.296Z"),
"value" : "Instant"
}
]
}