Files
mongo/jstests/core/indexapi.js
Charlie Swanson 298fc23192 SERVER-63947 Add column store jscore passthrough - plus fixes
Also fixes:
- $where reports depending on a full object, disqualifying it from using
  the column store index.
- projection analysis should not remove a projection if we have some
  match fields that are not needed in the output. This doesn't work yet.
2022-07-27 16:29:59 +00:00

68 lines
2.3 KiB
JavaScript

// Cannot implicitly shard accessed collections because of not being able to create unique index
// using hashed shard key pattern.
// @tags: [
// cannot_create_unique_index_when_using_hashed_shard_key,
// # Uses $indexStats which is not supported in a transaction.
// does_not_support_transactions,
// ]
(function() {
"use strict";
const coll = db.indexapi;
coll.drop();
const kTestKeyPattern = {
x: 1
};
const indexSpecObj = {
ns: coll._fullName,
key: kTestKeyPattern,
name: coll._genIndexName(kTestKeyPattern)
};
assert.eq(indexSpecObj, coll._indexSpec(kTestKeyPattern));
indexSpecObj.name = "bob";
assert.eq(indexSpecObj, coll._indexSpec(kTestKeyPattern, "bob"));
indexSpecObj.name = coll._genIndexName(kTestKeyPattern);
assert.eq(indexSpecObj, coll._indexSpec(kTestKeyPattern));
indexSpecObj.unique = true;
assert.eq(indexSpecObj, coll._indexSpec(kTestKeyPattern, true));
assert.eq(indexSpecObj, coll._indexSpec(kTestKeyPattern, [true]));
assert.eq(indexSpecObj, coll._indexSpec(kTestKeyPattern, {unique: true}));
indexSpecObj.dropDups = true;
assert.eq(indexSpecObj, coll._indexSpec(kTestKeyPattern, [true, true]));
assert.eq(indexSpecObj, coll._indexSpec(kTestKeyPattern, {unique: true, dropDups: true}));
function getSingleIndexWithKeyPattern(keyPattern) {
let allIndexes = coll.aggregate([
{$indexStats: {}},
{$match: {key: keyPattern}},
// Unnest the "$spec" field into top-level.
{$replaceWith: {$mergeObjects: ["$$ROOT", "$spec"]}}
])
.toArray();
assert.eq(allIndexes.length, 1);
return allIndexes[0];
}
coll.createIndex(kTestKeyPattern, {unique: true});
let allIndexes = coll.getIndexes();
assert.eq(2, allIndexes.length);
assert.sameMembers([kTestKeyPattern, {_id: 1}], allIndexes.map(entry => entry.key));
let xIndex = getSingleIndexWithKeyPattern(kTestKeyPattern);
assert.eq(xIndex.key, kTestKeyPattern);
assert(xIndex.unique, xIndex);
coll.drop();
coll.createIndex(kTestKeyPattern, {unique: 1});
allIndexes = coll.getIndexes();
assert.eq(2, allIndexes.length);
xIndex = getSingleIndexWithKeyPattern(kTestKeyPattern);
assert.eq(kTestKeyPattern, xIndex.key);
assert(xIndex.unique);
}());