summaryrefslogtreecommitdiff
path: root/jstests/aggregation/sources/geonear/collation_geonear.js
blob: d4c47c1aec0140d4077d22b3b99ef1a24b8811de (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Cannot implicitly shard accessed collections because of collection existing when none expected.
// @tags: [assumes_no_implicit_collection_creation_after_drop]

// Test that the $geoNear stage's query predicate respects the collation.
(function() {
"use strict";

const caseInsensitive = {
    collation: {locale: "en_US", strength: 2}
};

var coll = db.collation_geonear;
coll.drop();
assert.commandWorked(coll.createIndex({loc: "2dsphere"}));
assert.writeOK(coll.insert({loc: [0, 0], str: "A"}));

// Test that the $geoNear agg stage respects an explicit collation.
assert.eq(0,
          coll.aggregate([{
                  $geoNear: {
                      near: {type: "Point", coordinates: [0, 0]},
                      distanceField: "distanceField",
                      spherical: true,
                      query: {str: "a"},
                  }
              }])
              .itcount());
assert.eq(1,
          coll.aggregate([{
                             $geoNear: {
                                 near: {type: "Point", coordinates: [0, 0]},
                                 distanceField: "distanceField",
                                 spherical: true,
                                 query: {str: "a"},
                             }
                         }],
                         caseInsensitive)
              .itcount());

// Test that the collation parameter cannot be passed directly as a parameter of the $geoNear
// stage.
assert.throws(function() {
    coll.aggregate([{
        $geoNear: {
            near: {type: "Point", coordinates: [0, 0]},
            distanceField: "distanceField",
            spherical: true,
            query: {str: "a"},
            collation: {locale: "en_US", strength: 2},
        }
    }]);
});

coll.drop();
assert.commandWorked(db.createCollection(coll.getName(), caseInsensitive));
assert.commandWorked(coll.createIndex({loc: "2dsphere"}));
assert.writeOK(coll.insert({loc: [0, 0], str: "A"}));

// Test that the $geoNear agg stage respects an inherited collation.
assert.eq(1,
          coll.aggregate([{
                  $geoNear: {
                      near: {type: "Point", coordinates: [0, 0]},
                      distanceField: "distanceField",
                      spherical: true,
                      query: {str: "a"},
                  }
              }])
              .itcount());

// Test that the the collection default can be overridden with the simple collation.
assert.eq(0,
          coll.aggregate([{
                             $geoNear: {
                                 near: {type: "Point", coordinates: [0, 0]},
                                 distanceField: "distanceField",
                                 spherical: true,
                                 query: {str: "a"},
                             }
                         }],
                         {collation: {locale: "simple"}})
              .itcount());
})();