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

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -