how to in place update document : move element from one array to another ?

19 views
Skip to first unread message

Prashant Bhate

unread,
Oct 9, 2012, 4:19:18 PM10/9/12
to mongod...@googlegroups.com
With following document

Diagrams
{
name:'fig1',
pointsFrom:[point1,point2],
pointsTo:[],
moveCount:0
}


How to update above document and move point1 from pointsFrom to pointsTo array using collections.update api, without actually fetching complete object ?

update(
{name:'fig1'}, //criteria
{
 $inc:{moveCount:1}, 
 $pull: {pointsFrom:point1} ,
 $push:{pointsTo:point1}
},//Modifier
false,//upsert false
true //update multiple documents
)

Louisa Berger

unread,
Oct 9, 2012, 6:36:47 PM10/9/12
to mongod...@googlegroups.com
Currently, you cannot use the fields of your document when updating a different field in your document. There's a good example for how to do work arounds for this general problem here : http://stackoverflow.com/questions/3788256/mongodb-updating-documents-using-data-from-the-same-document/3792958#3792958
Reply all
Reply to author
Forward
0 new messages