summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod/validate_timeseries.js
blob: 5611bdcf13b2b31b53694c8a9b41214588f434dc (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
/*
 * Tests that calling the validate command on a time-series collection is allowed, while ensuring
 * that calling validate on non-time-series views is still prohibited, even if a collection with the
 * bucket namespace of that view exists.
 *
 * @tags: [
 * requires_fcv_62
 * ]
 */

(function() {
"use strict";

db.validate_timeseries.drop();
db.system.buckets.validate_timeseries.drop();
db.viewSource.drop();
db.view.drop();
db.system.buckets.view.drop();

assert.commandWorked(db.createCollection(
    "validate_timeseries",
    {timeseries: {timeField: "timestamp", metaField: "metadata", granularity: "hours"}}));

const coll = db.validate_timeseries;
const bucketColl = db.system.buckets.validate_timeseries;
const weather_data = [
    {
        "metadata": {"sensorId": 5578, "type": "temperature"},
        "timestamp": ISODate("2021-05-18T00:00:00.000Z"),
        "temp": 12
    },
    {
        "metadata": {"sensorId": 5578, "type": "temperature"},
        "timestamp": ISODate("2021-05-18T04:00:00.000Z"),
        "temp": 11
    },
];

assert.commandWorked(coll.insertMany(weather_data), {ordered: false});

// Tests that the validate command can be run on a time-series collection.

let res = assert.commandWorked(coll.validate());
assert(res.valid, tojson(res));

res = assert.commandWorked(bucketColl.validate());
assert(res.valid, tojson(res));

// Tests that the validate command doesn't run on a view without a bucket collection.
assert.commandWorked(db.createCollection("viewSource"));

assert.commandWorked(db.createView("view", "viewSource", [{$project: {"Name": "$temp"}}]));

const viewSource = db.viewSource;
const view = db.view;

res = assert.commandWorked(viewSource.validate());
assert(res.valid, tojson(res));

assert.commandFailedWithCode(view.validate(), ErrorCodes.CommandNotSupportedOnView);

// Tests that the validate command doesn't run on a view with a non-time-series bucket collection.
assert.commandWorked(db.createCollection("system.buckets.view"));

assert.commandFailedWithCode(view.validate(), ErrorCodes.CommandNotSupportedOnView);

//
})();