File: shard7.js

package info (click to toggle)
mongodb 1%3A3.2.11-2%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 196,404 kB
  • sloc: cpp: 1,412,793; ansic: 504,961; python: 78,522; perl: 5,837; sh: 5,661; java: 4,202; makefile: 1,784; pascal: 617; xml: 176; asm: 128
file content (54 lines) | stat: -rw-r--r-- 1,857 bytes parent folder | download
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Check that shard selection does not assert for certain unsatisfiable queries.
// SERVER-4554, SERVER-4914

s = new ShardingTest({name: 'shard7', shards: 2});

db = s.admin._mongo.getDB('test');
c = db['foo'];
c.drop();

s.adminCommand({enablesharding: '' + db});
s.ensurePrimaryShard(db.getName(), 'shard0001');
s.adminCommand({shardcollection: '' + c, key: {a: 1, b: 1}});

// Check query operation with some satisfiable and unsatisfiable queries.

assert.eq(0, c.find({a: 1}).itcount());
assert.eq(0, c.find({a: 1, b: 1}).itcount());
assert.eq(0, c.find({a: {$gt: 4, $lt: 2}}).itcount());
assert.eq(0, c.find({a: 1, b: {$gt: 4, $lt: 2}}).itcount());
assert.eq(0, c.find({a: {$gt: 0, $lt: 2}, b: {$gt: 4, $lt: 2}}).itcount());
assert.eq(0, c.find({b: {$gt: 4, $lt: 2}}).itcount());
assert.eq(0, c.find({a: {$in: []}}).itcount());
assert.eq(0, c.find({a: 1, b: {$in: []}}).itcount());

assert.eq(0, c.find({$or: [{a: {$gt: 0, $lt: 10}}, {a: 12}]}).itcount());
assert.eq(0, c.find({$or: [{a: {$gt: 0, $lt: 10}}, {a: 5}]}).itcount());
assert.eq(0, c.find({$or: [{a: 1, b: {$gt: 0, $lt: 10}}, {a: 1, b: 5}]}).itcount());

// Check other operations that use getShardsForQuery.

unsatisfiable = {
    a: 1,
    b: {$gt: 4, $lt: 2}
};

assert.eq(0, c.count(unsatisfiable));
assert.eq([], c.distinct('a', unsatisfiable));

aggregate = c.aggregate({$match: unsatisfiable});
assert.eq(0, aggregate.toArray().length);

c.save({a: null, b: null});
c.save({a: 1, b: 1});
assert.writeOK(c.remove(unsatisfiable));
assert.eq(2, c.count());
assert.writeOK(c.update(unsatisfiable, {$set: {c: 1}}, false, true));
assert.eq(2, c.count());
assert.eq(0, c.count({c: 1}));

c.ensureIndex({loc: '2d'});
c.save({a: 2, b: 2, loc: [0, 0]});
near = db.runCommand({geoNear: 'foo', near: [0, 0], query: unsatisfiable});
assert.commandWorked(near);
assert.eq(0, near.results.length);