I need to do a one-time bulk update and set signupDate
for a collection for fields that don't have it to be reminders[0].start
which is a date that these documents do have. Document may look like:
{
"_id" : ObjectId("545147655ce9ec369b8fa9bf"),
"reminder" : [{
"start" : ISODate("2014-11-01T04:00:00Z"),
"_id" : ObjectId("545147401f60bac766304334")
}],
}
So for this document I would need signupDate
to be ISODate("2014-11-01T04:00:00Z")
.
I could write a node.js script to find documents that don't have signupDate
and update them individually, but it would be nice to write a single query from the shell.
I see that there is a findAndModify
method I think would look a bit like:
db.collection.findAndModify({
query: {signupDate: {$exists:false}},
update: {signupDate: "?"}
});
Just not sure how to get the value of reminders[0].start
for the same document if that's even possible.