'Can I update a list in a collection using data from another collection in mongo?
I have 2 collections, Offers and Inventory
Offers
...
{
"_id": "<someid>",
"name": "Offer1",
"items": [
{
"id": "1234",
"itemName": "Apples"
},
{
"id": "2345",
"itemName": "Oranges"
}
]
},
{
"_id": "<someid>",
"name": "Offer2",
"items": [
{
"id": "1234",
"itemName": "Apples"
},
{
"id": "3456",
"itemName": "Bananas"
}
]
},
...
Inventory
...
{
"_id": "<someid>",
"id": "1234",
"shortName": "Apples",
"longName": "Malus domestica"
},
...
I would like to update the itemName in the Offers collection with the longName of the Inventory. Is it possible to do so directly in mongodb? Alternatively is there a simple way to do this in python?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
