How to correctly update embedded object's field in mongodb? -


how correctly update resetpasswordexpires field in mongodb document:

{      "_id" : objectid("000"),      "username" : "root",      "isactive" : "yes",      "email" : "email@gmail.com",      "roles" : {          "admin" : objectid("111")      },      "resetpasswordexpires" : isodate("2015-06-19t18:04:40.014z"),     "resetpasswordtoken" : "token"  } 

i tried:

db.users.update(     { item: "000" },     {       $set: {  "roles.resetpasswordexpires":  isodate("2015-06-20t18:04:40.014z")} }) 

and

db.users.update(     { item: "111" },     {       $set: {  "roles.resetpasswordexpires":  isodate("2015-06-20t18:04:40.014z")} }) 

and few other variations without matching.

the query needs match on _id (at least appears trying match on). update value resetpasswordexpires not property of roles. following should work:

db.users.update(   { _id: objectid("000") },   {$set: {  "resetpasswordexpires":  isodate("2015-06-20t18:04:40.014z")} }); 

Comments

Popular posts from this blog

symfony - TEST environment only: The database schema is not in sync with the current mapping file -

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -