0

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.

Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
  • possible duplicate of [Update MongoDB field using value of another field](http://stackoverflow.com/questions/3974985/update-mongodb-field-using-value-of-another-field) – Will Shaver Nov 18 '14 at 16:27
  • http://stackoverflow.com/questions/3974985/update-mongodb-field-using-value-of-another-field this is a common complaint about mongodb. You can vote for a method to solve this here: https://jira.mongodb.org/browse/SERVER-458 – Will Shaver Nov 18 '14 at 16:28

0 Answers0