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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -