2017-03-23 14:07:50 -04:00
|
|
|
// Cannot implicitly shard accessed collections because of following errmsg: A single
|
|
|
|
|
// update/delete on a sharded collection must contain an exact match on _id or contain the shard
|
|
|
|
|
// key.
|
2017-11-28 10:10:44 -05:00
|
|
|
// @tags: [assumes_unsharded_collection, requires_non_retryable_writes]
|
2017-03-23 14:07:50 -04:00
|
|
|
|
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);
|