Я пытаюсь обновить коллекцию, используя mongoose 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
, где merch.details.listcode
равно «ADS-100», я хотел бы знать, есть ли способ сделать этос FindOneAndUpdate
и $set
я использую Mongoose
"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"
},
]
У каждого мерча есть и ID, у каждой детали и ID, я пробовал
List.findOneAndUpdate(
{ "_id": listid, "merch.details._id": merchid },
{ $set: { "merch.details.$.listcode": "ADS-100B" }},
Но коллекцияне найден.