How to update date field in mongo console?

You need to create a new ISODate object like this:

db.test.insert({"Time" : new ISODate("2012-01-10") });

This is true both for updates and for queries. Note that your query syntax is incorrect, it should be

db.test.update({ criteria }, { newObj }, upsert, multi);

For example, to update all objects, consider

db.test.update( {}, { $set : { "time" : new ISODate("2012-01-11T03:34:54Z") } }, true, true);

Also note that this is very different from

db.test.update( {}, { "time" : new ISODate("2012-01-11T03:34:54Z") }, true, false);

because the latter will replace the object, rather than add a new field to the existing document or updating the existing field. In this example, I changed the last parameter to false, because multi updates only work with $ operators.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)