如何在猫鼬模型中保存子文档的数量?

时间:2019-01-15 15:33:52

标签: node.js mongodb mongoose mongoose-schema

我有一个这样的架构:

{
"_id": "5c3dfc99a524778e386aee41",
"userId": "5c3c7624188fd684580f605e",
"userName": "Devesh Vyas",
"description": "This is my first feed @ Paris",
"photos": [
    "https://www.telegraph.co.uk/content/dam/Travel/hotels/europe/france/paris/eiffel-tower-paris-p.jpg?imwidth=480",
    "https://www.telegraph.co.uk/content/dam/Travel/hotels/europe/france/paris/eiffel-tower-paris-p.jpg?imwidth=480"
],
"location": [
    {
        "lat": 12.971599,
        "lon": 77.594566
    }
],
"comments": [],
"likes": [],
"created_at": "2019-01-15T15:30:08.931Z",
"updated_at": "2019-01-15T15:30:08.931Z"

}

在创建文档时如何存储计数,当我更新文档时,猫鼬应该返回更新计数。我可以通过API调用来实现这一点,但它将是n + 1个api调用,以查找每个供稿的喜欢和评论计数。

0 个答案:

没有答案