summaryrefslogtreecommitdiff
path: root/jstests/core/datasize2.js
blob: a9d008e2ed1e674b8b3f9a60c36e7984d6272016 (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
// Cannot implicitly shard accessed collections because the "dataSize" command returns an
// "keyPattern must equal shard key" error response.
// @tags: [assumes_unsharded_collection, no_selinux]
//
// Test dataSize command, when called on the same or different database
// than the collection being queried.
//

(function() {
"use strict";

var coll = db.foo;
var adminDB = db.getSiblingDB('admin');
coll.drop();

var N = 1000;
for (var i = 0; i < N; i++) {
    coll.insert({_id: i, s: "asdasdasdasdasdasdasd"});
}

var dataSizeCommand =
    {"dataSize": "test.foo", "keyPattern": {"_id": 1}, "min": {"_id": 0}, "max": {"_id": N}};

assert.eq(N,
          db.runCommand(dataSizeCommand).numObjects,
          "dataSize command on 'test.foo' failed when called on the 'test' DB.");
assert.eq(N,
          adminDB.runCommand(dataSizeCommand).numObjects,
          "dataSize command on 'test.foo' failed when called on the 'admin' DB.");

dataSizeCommand.maxObjects = 100;
assert.eq(101,
          db.runCommand(dataSizeCommand).numObjects,
          "dataSize command with max number of objects set failed on 'test' DB");
assert.eq(101,
          db.runCommand(dataSizeCommand).numObjects,
          "dataSize command with max number of objects set failed on 'admin' DB");
})();