summaryrefslogtreecommitdiff
path: root/jstests/core/timeseries/timeseries_geonear.js
blob: 67747b23a113087180bb7202259367822da7d4cc (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
/**
 * Test that $geoNear, $near, $nearSphere, and $text are not allowed against timeseries collections
 * and such queries fail cleanly.
 *
 * @tags: [
 *     assumes_unsharded_collection,
 *     does_not_support_transactions,
 *     does_not_support_stepdowns,
 *     requires_fcv_51,
 *     requires_pipeline_optimization,
 *     requires_timeseries,
 * ]
 */

(function() {
"use strict";

load("jstests/core/timeseries/libs/timeseries.js");

if (!TimeseriesTest.timeseriesCollectionsEnabled(db.getMongo())) {
    jsTestLog("Skipping test because the time-series collection feature flag is disabled");
    return;
}

const timeFieldName = "time";
const metaFieldName = "tags";
const testDB = db.getSiblingDB(jsTestName());
assert.commandWorked(testDB.dropDatabase());

const tsColl = testDB.getCollection("ts_point_data");

assert.commandWorked(testDB.createCollection(
    tsColl.getName(), {timeseries: {timeField: timeFieldName, metaField: metaFieldName}}));

assert.commandWorked(tsColl.createIndex({'tags.loc': '2dsphere'}));

const nMeasurements = 10;

for (let i = 0; i < nMeasurements; i++) {
    const docToInsert = {
        time: ISODate(),
        tags: {loc: [40, 40], descr: i.toString()},
        value: i + nMeasurements,
    };
    assert.commandWorked(tsColl.insert(docToInsert));
}

let agg = tsColl.aggregate([{
    $geoNear: {
        near: {type: "Point", coordinates: [106.65589, 10.787627]},
        key: 'tags.loc',
        distanceField: "tags.distance",
    }
}]);
assert.eq(agg.itcount(), nMeasurements);

/* TODO (SERVER-58443): enable these tests once they work
assert.commandWorked(tsColl.find({"tags.distance": {$geoNear: [0, 0]}}).itcount());
assert.commandWorked(tsColl.find({"tags.distance": {$near: [0, 0]}}).itcount());
assert.commandWorked(tsColl
                         .find({
                             "tags.distance": {
                                 $nearSphere: {
                                     $geometry: {type: "Point", coordinates: [-73.9667, 40.78]},
                                     $minDistance: 10,
                                     $maxDistance: 20
                                 }
                             }
                         })
                         .itcount());*/
})();