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
|
2016-02-04 12:29:01 -05:00
|
|
|
coll.remove({});
|
2016-03-09 12:17:50 -05:00
|
|
|
coll.save({_id: 1, a: 2});
|
2016-02-04 12:29:01 -05:00
|
|
|
res = coll.update({}, {$currentDate: {a: true}});
|
2014-02-19 12:45:53 -05:00
|
|
|
assert.writeOK(res);
|
2016-02-04 12:29:01 -05:00
|
|
|
assert(coll.findOne().a.constructor == Date);
|
2013-12-09 14:45:13 -05:00
|
|
|
|
|
|
|
|
// $currentDate type = date
|
2016-02-04 12:29:01 -05:00
|
|
|
coll.remove({});
|
2016-03-09 12:17:50 -05:00
|
|
|
coll.save({_id: 1, a: 2});
|
2016-02-04 12:29:01 -05:00
|
|
|
res = coll.update({}, {$currentDate: {a: {$type: "date"}}});
|
2014-02-19 12:45:53 -05:00
|
|
|
assert.writeOK(res);
|
2016-02-04 12:29:01 -05:00
|
|
|
assert(coll.findOne().a.constructor == Date);
|
2013-12-09 14:45:13 -05:00
|
|
|
|
|
|
|
|
// $currentDate type = timestamp
|
2016-02-04 12:29:01 -05:00
|
|
|
coll.remove({});
|
2016-03-09 12:17:50 -05:00
|
|
|
coll.save({_id: 1, a: 2});
|
2016-02-04 12:29:01 -05:00
|
|
|
res = coll.update({}, {$currentDate: {a: {$type: "timestamp"}}});
|
2014-02-19 12:45:53 -05:00
|
|
|
assert.writeOK(res);
|
2016-02-04 12:29:01 -05:00
|
|
|
assert(coll.findOne().a.constructor == Timestamp);
|