如何为每个_id计算MongoDB的嵌入式文档

时间:2017-03-26 10:14:22

标签: mongodb

我的文档看起来像:

>>> import requests
>>> target_url = "https://www.thenews.com.pk/latest/category/sports/2015-09-21"
>>> response = requests.get(target_url)
>>> response.history[0].url
u'https://www.thenews.com.pk/latest/category/sports/2015-09-21'
>>> response.url
u'https://www.thenews.com.pk/'
>>> response.history and response.url == 'https://www.thenews.com.pk/' != target_url
True

如何计算状态="待定"来自嵌入式文件? 我希望结果看起来像:

_id: 1,
    chat: [
    {
     sender: "michael",
     message: "hello",
     status: "pending",
     receiver: "jennifer"
    },
    {
     sender: "michael",
     message: "how are you ?",
     status: "sent",
     receiver: "jennifer"
    }
    ]
_id: 2,
    chat: [
    {
     sender: "michael",
     message: "hello",
     status: "pending",
     receiver: "bobby"
    },
    {
     sender: "michael",
     message: "how are you ?",
     status: "pending",
     receiver: "bobby"
    }
    ]

我不知道如何在MongoDB中使用$ unwind,$ group,$ size。请有人帮帮我......

1 个答案:

答案 0 :(得分:0)

您可以先{id},ItemStack output = new ItemStack(Material.MONSTER_EGG, 1, <ENTITYID>); GameRegistry.addShapelessRecipe(output, new Object[]{ new ItemStack(r2d2body), new ItemStack(r2d2head) }); 通过ID,发件人和收件人进行聊天,并使用$unwind然后$group进行统计,以便返回最终结果。

$sum

最终结果

$project