javascript - Node.js update elements in MongoDB -
i have following mongoose schema , model:
var deviceschema = new schema({ deviceid:string, devicename:string, deviceplace:string, socket : [{number: number,name:string, state : boolean, current: number, image:number,locked:boolean,reserved:boolean}] });
i have device in database 4 sockets.
here example!
this original data.
{ "_id" : objectid("5626569006bc3da468bafe93"), "deviceid" : "0013a20040b5769a", "devicename" : "device", "deviceplace" : "place", "__v" : 0, "socket" : [ { "_id" : objectid("5628bd83570be84e28879e2d"), "number" : 0, "name" : "name" "state" : true, "current" : 0 "image" : 0, "locked" : false, "reserved" : false, }, ... ] }
and received data client update.
{ "_id" : objectid("5626569006bc3da468bafe93"), "deviceid" : "0013a20040b5769a", "__v" : 0, "socket" : [ { "_id" : objectid("5628bd83570be84e28879e2d"), "number" : 0, "name" : "new name!!!!!" "state" : true, "current" : 0 }, ... ] }
now i'm trying update specific socket's name in database following command:
device.update({deviceid: newdata.deviceid, "socket.number": newdata.number}, {$set: {"socket.$.name": newdata.name}})
newdata object extracted socket array in received data.
i want update first socket's name. or if possible, want update every socket's name received socket array.
but not seem working, no error. can pin point i'm doing wrong?
Comments
Post a Comment