I have quite a complex data structure in mongoDB. The document looks like a little like this
{
"id" : 0,
"basket" : [
{
"price" : 0.9918,
"id" : 2500,
"exGroup" : [
{
"exgId" : 0,
"ePrice" : 0.9918
}
{
"exgId" : 1,
"ePrice" : 0.9918
}
]
}, ]}
I would like to add an array of documents into the exGroup array of embedded documents so that each of the embedded documents looks like this
{
"id" : 0,
"price" : 0.9918
"order" : {
"id":0,
"exec":
[{
"quantity" : 1,
"price" : 1.0
},
{
"quantity" : 1,
"price" : 1.01
}
]
}
I have tried to do this with an update query that looks like this:
db.fund.update(
{
"id": 0,
"basket.id": 2500,
"basket.exGroup.exgId": 0,
"basket.exGroup.order": {"$exists" : false}
},
{
"$set":
{
"basket.exGroup.$.order" :
{
"id":0,
"exec":
[{
"quantity":1,
"price":0.9978
}]
}
}
}
)
Unfortunately this gives me the error "fundId": 0, "date": ISODate("2016-11-21T11:00:00.000+0000"), "basket.assetId": 2500, "basket.exGroup.exgId": 0
Fundamentally my problem is that I don't know how to correctly address a document that is at the leaf of a multi level array (i.e. doc.array.doc.array.doc)