summaryrefslogtreecommitdiff
path: root/jstests/core/geo_2d_trailing_fields.js
blob: aa66832281d472fa0d2f392cd63707aab837645b (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Tests for predicates which can use the trailing field of a 2d index.
(function() {
"use strict";

const coll = db.geo_2d_trailing_fields;

coll.drop();
assert.commandWorked(coll.createIndex({a: "2d", b: 1}));
assert.commandWorked(coll.insert({a: [0, 0]}));

// Verify that $near queries handle existence predicates over the trailing fields correctly.
assert.eq(0, coll.find({a: {$near: [0, 0]}, b: {$exists: true}}).itcount());
assert.eq(1, coll.find({a: {$near: [0, 0]}, b: null}).itcount());
assert.eq(1, coll.find({a: {$near: [0, 0]}, b: {$exists: false}}).itcount());

// Verify that non-near 2d queries handle existence predicates over the trailing fields
// correctly.
assert.eq(0, coll.find({a: {$geoWithin: {$center: [[0, 0], 1]}}, b: {$exists: true}}).itcount());
assert.eq(1, coll.find({a: {$geoWithin: {$center: [[0, 0], 1]}}, b: null}).itcount());
assert.eq(1, coll.find({a: {$geoWithin: {$center: [[0, 0], 1]}}, b: {$exists: false}}).itcount());

coll.drop();
assert.commandWorked(coll.createIndex({a: "2d", "b.c": 1}));
assert.commandWorked(coll.insert({a: [0, 0], b: [{c: 2}, {c: 3}]}));

// Verify that $near queries correctly handle predicates which cannot be covered due to array
// semantics.
assert.eq(0, coll.find({a: {$near: [0, 0]}, "b.c": [2, 3]}).itcount());
assert.eq(0, coll.find({a: {$near: [0, 0]}, "b.c": {$type: "array"}}).itcount());

// Verify that non-near 2d queries correctly handle predicates which cannot be covered due to
// array semantics.
assert.eq(0, coll.find({a: {$geoWithin: {$center: [[0, 0], 1]}}, "b.c": [2, 3]}).itcount());
assert.eq(0,
          coll.find({a: {$geoWithin: {$center: [[0, 0], 1]}}, "b.c": {$type: "array"}}).itcount());

coll.drop();
assert.commandWorked(coll.createIndex({a: "2d", "b.c": 1}));
assert.commandWorked(coll.insert({a: [0, 0], b: [{c: 1}, {c: 2}]}));

// Verify that non-near 2d queries correctly handle predicates which cannot be covered due to
// array semantics.
assert.eq(1,
          coll.find({a: {$geoWithin: {$center: [[0, 0], 1]}}, b: {$elemMatch: {c: 1}}}).itcount());
}());