summaryrefslogtreecommitdiff
path: root/jstests/aggregation/sources/densify/mixed_units.js
blob: b56c2074e96908575fca89c74a33b4c45da2a30d (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/**
 * Test that $densify fails with the right uassert codes when collections have values with the wrong
 * types, and mixed value types in the same collection.
 * @tags: [
 *   # Needed as $densify is a 51 feature.
 *   requires_fcv_51,
 * ]
 */
(function() {
"use strict";

load("jstests/aggregation/extras/utils.js");  // For arrayEq.

const coll = db[jsTestName()];
coll.drop();

// Densification on a numeric collection with a date step.
assert.commandWorked(coll.insert([{val: 1}, {val: 3}, {val: 5}]));
assert.commandFailedWithCode(db.runCommand({
    aggregate: coll.getName(),
    pipeline: [{$densify: {field: "val", range: {step: 1, bounds: "full", unit: "day"}}}],
    cursor: {}
}),
                             6053600);

coll.drop();

// Densification on a date collection with a numeric step.
assert.commandWorked(coll.insert([
    {val: new ISODate("2021-01-01")},
    {val: new ISODate("2021-01-03")},
    {val: new ISODate("2021-01-05")}
]));
assert.commandFailedWithCode(db.runCommand({
    aggregate: coll.getName(),
    pipeline: [{$densify: {field: "val", range: {step: 1, bounds: "full"}}}],
    cursor: {}
}),
                             6053600);
coll.drop();

// Densification on a mixed collection with a numeric step and a first value that's numeric.
assert.commandWorked(coll.insert([
    {val: 1},
    {val: new ISODate("2021-01-01")},
    {val: new ISODate("2021-01-03")},
    {val: new ISODate("2021-01-05")}
]));
assert.commandFailedWithCode(db.runCommand({
    aggregate: coll.getName(),
    pipeline: [{$densify: {field: "val", range: {step: 1, bounds: "full"}}}],
    cursor: {}
}),
                             6053600);
coll.drop();

// Densification on a mixed collection with a date step and a first value that's numeric.
assert.commandWorked(coll.insert([
    {val: 1},
    {val: new ISODate("2021-01-01")},
    {val: new ISODate("2021-01-03")},
    {val: new ISODate("2021-01-05")}
]));
assert.commandFailedWithCode(db.runCommand({
    aggregate: coll.getName(),
    pipeline: [{$densify: {field: "val", range: {step: 1, bounds: "full", unit: "day"}}}],
    cursor: {}
}),
                             6053600);
coll.drop();

// Densification on a mixed collection with a numeric step and a first value that's a date.
assert.commandWorked(coll.insert([
    {val: new ISODate("2021-01-01")},
    {val: new ISODate("2021-01-03")},
    {val: 1},
    {val: new ISODate("2021-01-05")}
]));
assert.commandFailedWithCode(db.runCommand({
    aggregate: coll.getName(),
    pipeline: [{$densify: {field: "val", range: {step: 1, bounds: "full"}}}],
    cursor: {}
}),
                             6053600);

coll.drop();
// Densification on a mixed collection with a date step and a first value that's a date.
assert.commandWorked(coll.insert([
    {val: new ISODate("2021-01-01")},
    {val: new ISODate("2021-01-03")},
    {val: 1},
    {val: new ISODate("2021-01-05")}
]));
assert.commandFailedWithCode(db.runCommand({
    aggregate: coll.getName(),
    pipeline: [{$densify: {field: "val", range: {step: 1, bounds: "full", unit: "day"}}}],
    cursor: {}
}),
                             6053600);

coll.drop();
})();