mongodb / mongoose将动态字段添加到特定ID

时间:2019-02-25 17:42:02

标签: javascript node.js mongodb mongoose

我有这份文档,其中包含更多数据。

{
 id: xxx,
 year: xxx,
 cabins: xxx,
....,
....,
.... ,
}

我从客户端收到此对象

{
"filters":{
    "bathroom": [],
    "boatTypes": [],
    "cabins": [],
    "company": null,
    "equipment": [],
    "model": null,
    "people": [],
    "size": [],
    "year": []
},
"page": 1,
"sorts": {"year": -1, "cabins": 0, "price": -1},
"deals": [{"id":"1168172490000100171","price":1436},{"id":"5022940588601002","price":1020},{"id":"1947173240000102193","price":2140},{"id":"5375730661501802","price":1357},{"id":"912820359200870","price":825},{"id":"1154234500000101883","price":1440},{"id":"1471227690000103021","price":1200},{"id":"405297340000100171","price":1553},{"id":"648386010000100171","price":1328}] 
}

我正在尝试将价格字段添加到文档中,然后按年份价格和长度进行排序,有什么想法如何在不影响原始收藏的情况下做到这一点?

现在,我正在运行一个查询构建,以过滤来自客户端的所有内容,并按年份,客舱及其工作方式进行排序,价格来自客户端,而不起作用。非常感谢!

0 个答案:

没有答案