如何获取大于特定日期的子文档的计数。 假设我有以下模型,我希望获得大于特定日期的聊天计数。Mongodb获得特定字段的计数
model = {
"chats" : [
{
"comment" : "hi",
"_id" : ObjectId("576a2107aa7940f029ce6547"),
"createdDateTime" : ISODate("2016-06-22T05:24:23.422Z")
},
{
"comment" : "asdasdsa",
"_id" : ObjectId("576a2367aa7940f029ce6548"),
"createdDateTime" : ISODate("2016-06-22T05:34:31.628Z")
},
{
"comment" : "dsadasd",
"_id" : ObjectId("576a2369aa7940f029ce6549"),
"createdDateTime" : ISODate("2016-06-22T05:34:33.354Z")
},
],}
我已经与
Model.count({
$and: [
{ 'chats.createdDateTime': {$lt: '2016-06-22T10:03:21.879Z' } }, { '_id':messages[index]._id }
]
})
尝试也试过一些其他类似的方法。 任何人都可以帮助我吗?
如果可能的话请建议使用聚合框架。
我不认为有可能没有聚合。 – Shrabanee
好吧,但在这里我列出了数据,并且需要在特定日期之后统计每个列表聊天。你能建议一种方法吗? –
您正在使用的mongodb的版本是什么? – Shrabanee