Skip to content

Instantly share code, notes, and snippets.

@DiannaHohensee
Last active April 2, 2021 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DiannaHohensee/24e563dede54787bb65a073dadc71c90 to your computer and use it in GitHub Desktop.
Save DiannaHohensee/24e563dede54787bb65a073dadc71c90 to your computer and use it in GitHub Desktop.
jsTestLog("Testing wildcard index on time-series collection.");
resetCollections();
// Create a wildcard index on the time-series collection.
const wildcardTimeseriesIndexSpec = {
[metaFieldName + '.$**']: 1
};
const wildcardBucketsIndexSpec = {
['meta.$**']: 1
};
assert.commandWorked(
timeseriescoll.createIndex(wildcardTimeseriesIndexSpec),
'Failed to create a wildcard index with: ' + tojson(wildcardTimeseriesIndexSpec));
const wildcard1Doc = {
_id: 0,
[timeFieldName]: ISODate(),
[metaFieldName]: {a: 1, b: 1, c: {d: 1, e: 1}},
};
const wildcard2Doc = {
_id: 1,
[timeFieldName]: ISODate(),
[metaFieldName]: {a: 2, b: 2, c: {d: 1, e: 2}},
};
const wildcard3Doc = {
_id: 0,
[timeFieldName]: ISODate(),
[metaFieldName]:
{a: 3, b: 3, c: {d: 3, e: 3}, d: [{zip: '01234', town: 'nyc'}, {zip: '43210', town: 'sf'}]},
};
assert.commandWorked(timeseriescoll.insert(wildcard1Doc));
assert.commandWorked(timeseriescoll.insert(wildcard2Doc));
assert.commandWorked(timeseriescoll.insert(wildcard3Doc));
const bucketsWildcardFindExplain =
assert.commandWorked(bucketscoll.find().hint(wildcardBucketsIndexSpec).explain());
const planWildcardStage =
getPlanStage(getWinningPlan(bucketsWildcardFindExplain.queryPlanner), "IXSCAN");
assert.eq(true,
planWildcardStage.isMultiKey,
"Index should have been marked as multikey: " + tojson(planWildcardStage));
assert.eq({"meta.a": ["meta.a"]},
planWildcardStage.multiKeyPaths,
"Index has wrong multikey paths after insert; plan: " + tojson(planWildcardStage));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment