summaryrefslogtreecommitdiff
path: root/jstests/core/geo1.js
blob: 8a80f59d69237e787bd019a02e830151e38fbb16 (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
46
// Cannot implicitly shard accessed collections because of extra shard key index in sharded
// collection.
// @tags: [
//   assumes_no_implicit_index_creation,
//   requires_fastcount,
// ]

t = db.geo1;
t.drop();

idx = {
    loc: "2d",
    zip: 1
};

t.insert({zip: "06525", loc: [41.352964, 73.01212]});
t.insert({zip: "10024", loc: [40.786387, 73.97709]});
assert.commandWorked(t.insert({zip: "94061", loc: [37.463911, 122.23396]}));

// test "2d" has to be first
assert.eq(1, t.getIndexKeys().length, "S1");
t.createIndex({zip: 1, loc: "2d"});
assert.eq(1, t.getIndexKeys().length, "S2");

t.createIndex(idx);
assert.eq(2, t.getIndexKeys().length, "S3");

assert.eq(3, t.count(), "B1");
assert.writeError(t.insert({loc: [200, 200]}));
assert.eq(3, t.count(), "B3");

// test normal access

wb = t.findOne({zip: "06525"});
assert(wb, "C1");

assert.eq("06525", t.find({loc: wb.loc}).hint({"$natural": 1})[0].zip, "C2");
assert.eq("06525", t.find({loc: wb.loc})[0].zip, "C3");
// assert.eq( 1 , t.find( { loc : wb.loc } ).explain().nscanned , "C4" )

// test config options

t.drop();

t.createIndex({loc: "2d"}, {min: -500, max: 500, bits: 4});
assert.commandWorked(t.insert({loc: [200, 200]}));