javascript - Update dependent Date field in Mongoose -
i have documents in mongoose (mongodb):
{ begin: date, end: date }
all i'd to:
- select documents
end == null
- and update them using
end =
"begin increased 10 days"
how can done within single update?
right now, cannot reference document's current properties in update()
. instead, you'll have iterate through documents as described in answer. in case, more this:
db.docs.find({end:null}).foreach( function(doc) { doc.end = doc.begin + 10; db.docs.save(doc); } )
this syntax mongo shell-- might have make changes mongoose, as per api.
Comments
Post a Comment