summaryrefslogtreecommitdiff
path: root/jstests/readonly/geo.js
blob: 367cb89be96cae65e63ee2a49a75cf435b485ce1 (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
load('jstests/readonly/lib/read_only_test.js');

runReadOnlyTest(function() {
    'use strict';

    return {
        name: 'geo',

        load: function(writableCollection) {
            assert.commandWorked(writableCollection.createIndex({loc: "2dsphere"}));

            var locDocs = [
                {name: "Berry Park", loc: {type: "Point", coordinates: [40.722396, -73.9573645]}},
                {
                  name: "Northern Territory",
                  loc: {type: "Point", coordinates: [40.7252334, -73.9595218]}
                },
                {
                  name: "Kent Ale House",
                  loc: {type: "Point", coordinates: [40.7223364, -73.9614495]}
                },
                {name: "The Shanty", loc: {type: "Point", coordinates: [40.7185752, -73.9510538]}},
                {
                  name: "The Counting Room",
                  loc: {type: "Point", coordinates: [40.7209601, -73.9588041]}
                },
                {
                  name: "Kinfolk 94",
                  loc: {type: "Point", coordinates: [40.7217058, -73.9605489]}
                }
            ];

            writableCollection.insertMany(locDocs);
        },
        exec: function(readableCollection) {
            var res = readableCollection.find({
                loc:
                    {$near: {$geometry: {type: "Point", coordinates: [40.7211404, -73.9591494]}}}
            }).limit(1).toArray();
            assert.eq(res[0].name, "The Counting Room");
        }
    };
}());