summaryrefslogtreecommitdiff
path: root/jstests/core/find_size.js
blob: 0293c3e2b5679c4b761057ae48c66077765590d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Basic test for $size.

var t = db.jstests_find_size;
t.drop();

t.save({arr: []});
t.save({arr: []});
t.save({arr: [1]});
t.save({arr: [1, 2, 3, 4]});

// ints and longs
assert.eq(2, t.count({arr: {$size: 0}}));
assert.eq(2, t.count({arr: {$size: NumberLong(0)}}));
assert.eq(1, t.count({arr: {$size: NumberInt(4)}}));

// bad inputs
var badInputs = [-1, NumberLong(-10000), "str", 3.2, 0.1, NumberLong(-9223372036854775808)];
badInputs.forEach(function(x) { 
    assert.commandFailed(db.runCommand({count: t.getName(), query: {arr: {$size: x}}}),
                         "$size argument " + x + " should have failed"); 
});