summaryrefslogtreecommitdiff
path: root/jstests/core/datasize_validation.js
blob: c0f9c9d67b28338a75b4560f72a11c184e637481 (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
// Cannot implicitly shard accessed collections because the "dataSize" command returns an
// "keyPattern must equal shard key" error response.
// @tags: [assumes_unsharded_collection, requires_fcv_53]

//
// Test argument validation for dataSize command
//

(function() {
let coll = db[jsTestName()];
coll.drop();
coll.insertOne({_id: 1});
coll.insertOne({_id: 2});
coll.insertOne({_id: 3});
coll.insertOne({_id: 4});

assert.commandFailed(db.runCommand({
    'dataSize': coll.getFullName(),
    min: NumberLong("1"),
    max: NumberLong("2"),
    estimate: false
}),
                     "min and max should be objects");

assert.commandFailed(
    db.runCommand({'dataSize': coll.getFullName(), min: {_id: NumberLong("1")}, estimate: false}),
    "min and max should both be present");
assert.commandFailed(
    db.runCommand({'dataSize': coll.getFullName(), max: {_id: NumberLong("2")}, estimate: false}),
    "min and max should both be present");

let resultWithKey = assert.commandWorked(db.runCommand({
    'dataSize': coll.getFullName(),
    keyPattern: {_id: 1},
    min: {_id: NumberLong("1")},
    max: {_id: NumberLong("2")},
    estimate: false
}));
assert.eq(1, resultWithKey.numObjects, "only 1 object should be inspected between min/max bounds.");

let result = assert.commandWorked(db.runCommand({
    'dataSize': coll.getFullName(),
    min: {_id: NumberLong("1")},
    max: {_id: NumberLong("2")},
    estimate: false
}));
assert.eq(result.size,
          resultWithKey.size,
          "measured size should be equal after keyPattern properly inferred from min/max bounds.");
assert.eq(result.numObjects,
          resultWithKey.numObjects,
          "numObjects should be equal after keyPattern properly inferred from min/max bounds.");
})();