我正在尝试使用猫鼬Model.FindOneAndUpdate
更新集合。
这是我的数据结构:
{
"_id": "5c61d7d73815a42ae87b5f40",
"shipname": "pacatu",
"shipnumber": "28D",
"merch": [
{
"details": [
{
"_id": "5c6480e97ad72c2020b6d9c3",
"listcode": "ADS-100",
"merchtype": "Suelta",
"ton": 40
},
{
"_id": "5c6480e97ad72c2020b6d9c2",
"listcode": "ADS-101",
"merchtype": "Suelta",
"ton": 40
}
],
"_id": "5c6480e97ad72c2020b6d9c1",
"agency": "5c537c87552c430d58e4324d",
"updatedAt": "2019-02-13T20:41:13.121Z",
"createdAt": "2019-02-13T20:41:13.121Z"
},
{
"details": [
{
"_id": "5c61d9bb3815a42ae87b5f46",
"listcode": "ADS-213",
"merchtype": "Suelta",
"ton": 40
},
{
"_id": "5c61d9bb3815a42ae87b5f45",
"listcode": "ADS-215",
"merchtype": "Suelta",
"ton": 40
}
],
"_id": "5c61d9bb3815a42ae87b5f44",
"agency": "5c537c87552c430d58e4324d",
"createdAt": "2019-02-11T20:23:23.548Z",
"updatedAt": "2019-02-11T20:23:23.548Z"
},
{
"details": [
{
"_id": "5c64371598ba4010282421c0",
"listcode": "ADS-219",
"merchtype": "Suelta",
"ton": 40
},
{
"_id": "5c64371598ba4010282421bf",
"listcode": "ADS-220",
"merchtype": "Suelta",
"ton": 40
}
],
"_id": "5c64371598ba4010282421be",
"agency": "5c64367298ba4010282421bd",
"createdAt": "2019-02-13T15:26:13.140Z",
"updatedAt": "2019-02-13T15:26:13.140Z"
}
],
"createdAt": "2019-02-11T20:15:19.978Z",
"updatedAt": "2019-02-13T20:41:13.121Z",
"__v": 2
}
我想编辑listcode
等于“ ADS-100”的merch.details.listcode
字段,我想知道是否有一种方法可以使用FindOneAndUpdate
和{ {1}},我在用猫鼬
$set
每个商品都有ID,每个细节都有ID,我已经尝试过
"merch": [
{
"details": [
{
"_id": "5c6480e97ad72c2020b6d9c3",
"listcode": "ADS-100",
"merchtype": "Suelta",
"ton": 40
},
{
"_id": "5c6480e97ad72c2020b6d9c2",
"listcode": "ADS-101",
"merchtype": "Suelta",
"ton": 40
}
],
"_id": "5c6480e97ad72c2020b6d9c1",
"agency": "5c537c87552c430d58e4324d",
"updatedAt": "2019-02-13T20:41:13.121Z",
"createdAt": "2019-02-13T20:41:13.121Z"
},
]
但是找不到集合。