node.js - Mongodb Update Query Deletes All Array Fields Except Field Specified in Command -
i'm using node, mongodb, , mongoose. i've checked mongodb docs on set , update. i've googled little on hour , i've found topics dance around issue, nothing definitive though. query below updates correct field, removes other fields in array haven't specified.
db.posts.update( { "_id" : { $exists : true } }, { $set : { usercreated : { "time" : new isodate("2013-07-11t03:34:54z") } } }, false, true )
this section of schema i'm trying modify:
}, usercreated: { id: { type: mongoose.schema.types.objectid, ref: 'user' }, name: { type: string, default: '' }, time: { type: date, default: date.now } },
this comes out:
}, "usercreated": { "time": { isodate("2013-07-11t03:34:54z") } },
you can update time
property of usercreated
, leave other properties alone using dot notation:
db.posts.update( { "_id" : { $exists : true } }, { $set : { "usercreated.time" : new isodate("2013-07-11t03:34:54z") } }, false, true )
Comments
Post a Comment