summaryrefslogtreecommitdiff
path: root/jstests/core/wildcard_index_dedup.js
blob: 093d3e9d219b757b2997bd03fa0b979c187da377 (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
/**
 * Confirms that queries which scan multiple paths in a single wildcard index do not return
 * duplicate documents. For example, the object {a: {b: 1, c: 1}} will generate $** index keys with
 * paths "a.b" and "a.c". An index scan that covers both paths should deduplicate the documents
 * scanned and return only a single object.
 */
(function() {
"use strict";

const coll = db.wildcard_index_dedup;
coll.drop();

assert.commandWorked(coll.createIndex({"$**": 1}));

assert.commandWorked(coll.insert({a: {b: 1, c: {f: 1, g: 1}}, d: {e: [1, 2, 3]}}));

// An $exists that matches multiple $** index paths from nested objects does not return
// duplicates of the same object.
assert.eq(1, coll.find({a: {$exists: true}}).hint({"$**": 1}).itcount());

// An $exists that matches multiple $** index paths from nested array does not return
// duplicates of the same object.
assert.eq(1, coll.find({d: {$exists: true}}).hint({"$**": 1}).itcount());

// An $exists with dotted path that matches multiple $** index paths from nested objects
// does not return duplicates of the same object.
assert.eq(1, coll.find({"a.c": {$exists: true}}).hint({"$**": 1}).itcount());
})();