2013-12-09 14:45:13 -05:00
|
|
|
// Basic examples for $currentDate
|
2014-02-19 12:45:53 -05:00
|
|
|
var res;
|
2013-12-09 14:45:13 -05:00
|
|
|
var coll = db.update_currentdate;
|
|
|
|
|
coll.drop();
|
|
|
|
|
|
|
|
|
|
// $currentDate default
|
2014-02-02 11:21:12 -05:00
|
|
|
coll.remove({})
|
2013-12-09 14:45:13 -05:00
|
|
|
coll.save({_id:1, a:2});
|
2014-02-19 12:45:53 -05:00
|
|
|
res = coll.update({}, {$currentDate: {a: true}})
|
|
|
|
|
assert.writeOK(res);
|
2013-12-09 14:45:13 -05:00
|
|
|
assert(coll.findOne().a.constructor == Date)
|
|
|
|
|
|
|
|
|
|
// $currentDate type = date
|
2014-02-02 11:21:12 -05:00
|
|
|
coll.remove({})
|
2013-12-09 14:45:13 -05:00
|
|
|
coll.save({_id:1, a:2});
|
2014-02-19 12:45:53 -05:00
|
|
|
res = coll.update({}, {$currentDate: {a: {$type: "date"}}})
|
|
|
|
|
assert.writeOK(res);
|
2013-12-09 14:45:13 -05:00
|
|
|
assert(coll.findOne().a.constructor == Date)
|
|
|
|
|
|
|
|
|
|
// $currentDate type = timestamp
|
2014-02-02 11:21:12 -05:00
|
|
|
coll.remove({})
|
2013-12-09 14:45:13 -05:00
|
|
|
coll.save({_id:1, a:2});
|
2014-02-19 12:45:53 -05:00
|
|
|
res = coll.update({}, {$currentDate: {a: {$type: "timestamp"}}})
|
|
|
|
|
assert.writeOK(res);
|
2014-02-02 11:21:12 -05:00
|
|
|
assert(coll.findOne().a.constructor == Timestamp)
|