I have documents stored in collection that has form:
{
_id: ObjectId(""),
...
match:{
status: 'active',
list: [{
_id: ObjectId("") // a referance to another document
status: 'active' // can be active, seen, send
},{
..
}, ..]
}
}
I do a collection('A').find()
to retrieve this document and then retrieve all reference objects collection('B').find()
. Everything is sent to browser for human inspection.
Lets say that there are 10 B's associated with particular document form collection A. In browser admin marks three of them to send out. Now the document A look like this:
{
_id: ObjectId(""),
...
match:{
status: 'active',
list: [{
_id: ObjectId("")
status: 'seen'
},{
_id: ObjectId("")
status: 'send'
}, ..]
}
}
Basically from our 10 B's three were marked as "send" but all the rest (7 in this example) marked as seen.
Now the A is sent back to server and should be updated. The simple way to do that would be
db.collection('A').update({_id: a._id}, {$set{match.list: a.match.list}}, function(err, result){..});
But there is a problem. The time for admin to inspect the set could be quite long, up to an hour. There is a high possiblity that a new associated B could be pushed in A.
I could pull out the items that first and then push the new values but that seems ugly. Is there a built-in way to handle this situation? I need to update only specific items in array.
I checked the $ positional operator but it seem that i will match only one object in array.