我共有3个集: 1.用户 2.帖子 3.行动查询的MongoDB摆脱集合计数的参考ID阵列
我的藏品看起来像这些:
用户:
{
"_id" : ObjectId("57ee65fef5a0c032877725db"),
"fbId" : "EAAXZA4sZCZBKmgBAKe0JpJPrp7utWME6xbHT9yFD",
"name" : "Aftab",
"email" : "[email protected]",
"gender" : "male",
"__v" : NumberInt(0),
"updatedAt" : ISODate("2016-10-10T05:11:35.344+0000"),
"score" : NumberInt(90)
}
操作:
个{
"_id" : ObjectId("57f7a0ba3a603627658afdd3"),
"updatedAt" : ISODate("2016-10-07T13:18:50.815+0000"),
"createdAt" : ISODate("2016-10-07T13:18:50.815+0000"),
"userId" : ObjectId("57ee65fef5a0c032877725db"),
"postId" : ObjectId("57f4b5e98899081203883a1b"),
"type" : "like"
}
{
"_id" : ObjectId("57f7a0ba3a603627658afdd4"),
"updatedAt" : ISODate("2016-10-07T13:18:50.815+0000"),
"createdAt" : ISODate("2016-10-07T13:18:50.815+0000"),
"userId" : ObjectId("57ee65fef5a0c032877725db"),
"postId" : ObjectId("57f4b5d58899081203883a1a"),
"type" : "dismiss"
}
帖子:
{
"_id" : ObjectId("57f24593e272b5199e9351b9"),
"imgFileLocation" : "http://xxxx/buybye-platform/uploads/image-1475495315229",
"description" : "cool cool",
"title" : "Bad Image ",
"userId" : ObjectId("57f21e3d0b787d0f7ad76dd0"),
"__v" : NumberInt(0)
}
{
"_id" : ObjectId("57f4b5d58899081203883a1a"),
"imgFileLocation" : "http://xxx/buybye-platform/uploads/image-1475655125125",
"description" : "cool & cool",
"title" : "Good Image",
"userId" : ObjectId("57f21e3d0b787d0f7ad76dd0"),
"__v" : NumberInt(0)
}
用户可以创建的帖子,并且其他用户可以在这些帖子
帖集合具有用户id 和动作集合的参考执行操作具有用户id的REF(谁执行该操作),postId(在哪个帖子)和动作类型(喜欢/不喜欢/解雇)
我需要查询以获取所有在特定的用户帖子
我已经能够得到所有帖子对用户,这是非常直接,是一个数组。现在我需要在此帖子数组的每个帖子上执行所有操作。
你愿意更新你的问题与集合中的一些示例文档以及期望的聚合的预期输出?这有助于澄清问题并鼓励高质量的答案。 – chridam
你正在运行哪个MongoDB版本? – styvane
mongodb v3.2 @Styvane –