blob: ef84cff36351deedfef38c5c0ee0be95c6141e5a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
// Basic examples for $min/$max
var coll = db.update_min_max;
coll.drop();
// $min for number
coll.insert({_id:1, a:2});
coll.update({_id:1}, {$min: {a: 1}})
assert.gleSuccess(coll.getDB())
assert.eq(coll.findOne({_id:1}).a, 1)
// $max for number
coll.insert({_id:2, a:2});
coll.update({_id:2}, {$max: {a: 1}})
assert.gleSuccess(coll.getDB())
assert.eq(coll.findOne({_id:2}).a, 2)
// $min for Date
coll.insert({_id:3, a: new Date()});
var origDoc = coll.findOne({_id:3})
sleep(2)
coll.update({_id:3}, {$min: {a: new Date()}})
assert.gleSuccess(coll.getDB())
assert.eq(coll.findOne({_id:3}).a, origDoc.a)
// $max for Date
coll.insert({_id:4, a: new Date()});
sleep(2)
var newDate = new Date();
coll.update({_id:4}, {$max: {a: newDate}})
assert.gleSuccess(coll.getDB())
assert.eq(coll.findOne({_id:4}).a, newDate)
|