2018-04-06 10:33:03 -04:00
|
|
|
// @tags: [requires_getmore, requires_fastcount]
|
2017-11-28 10:10:44 -05:00
|
|
|
|
2017-03-13 12:16:34 -04:00
|
|
|
/**
|
|
|
|
|
* Inserts documents with an indexed nested document field, progressively increasing the nesting
|
|
|
|
|
* depth until the key is too large to index. This tests that we support at least the minimum
|
|
|
|
|
* supported BSON nesting depth, as well as maintaining index consistency.
|
|
|
|
|
*/
|
|
|
|
|
function makeNestObj(depth) {
|
|
|
|
|
if (depth == 1) {
|
|
|
|
|
return {a: 1};
|
|
|
|
|
} else {
|
|
|
|
|
return {a: makeNestObj(depth - 1)};
|
2012-07-12 14:14:38 -04:00
|
|
|
}
|
2019-07-26 18:20:35 -04:00
|
|
|
}
|
2012-07-12 14:14:38 -04:00
|
|
|
|
2017-03-13 12:16:34 -04:00
|
|
|
let collection = db.objNestTest;
|
|
|
|
|
collection.drop();
|
2012-07-12 14:14:38 -04:00
|
|
|
|
2020-11-17 13:45:05 +00:00
|
|
|
assert.commandWorked(collection.createIndex({a: 1}));
|
2012-07-12 14:14:38 -04:00
|
|
|
|
2017-03-13 12:16:34 -04:00
|
|
|
const kMaxDocumentDepthSoftLimit = 100;
|
|
|
|
|
const kJavaScriptMaxDepthLimit = 150;
|
2012-07-12 14:14:38 -04:00
|
|
|
|
2017-03-13 12:16:34 -04:00
|
|
|
let level;
|
|
|
|
|
for (level = 1; level < kJavaScriptMaxDepthLimit - 3; level++) {
|
|
|
|
|
let object = makeNestObj(level);
|
|
|
|
|
let res = db.runCommand({insert: collection.getName(), documents: [makeNestObj(level)]});
|
|
|
|
|
if (!res.ok) {
|
|
|
|
|
assert.commandFailedWithCode(
|
|
|
|
|
res, 17280, "Expected insertion to fail only because key is too large to index");
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-07-26 18:20:35 -04:00
|
|
|
}
|
2012-07-12 14:14:38 -04:00
|
|
|
|
2017-03-13 12:16:34 -04:00
|
|
|
assert.gt(level,
|
|
|
|
|
kMaxDocumentDepthSoftLimit,
|
|
|
|
|
"Unable to insert a document nested with " + level +
|
|
|
|
|
" levels, which is less than the supported limit of " + kMaxDocumentDepthSoftLimit);
|
|
|
|
|
assert.eq(collection.count(),
|
|
|
|
|
collection.find().hint({a: 1}).itcount(),
|
|
|
|
|
"Number of documents in collection does not match number of entries in index");
|