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
39
40
41
42
|
/**
* Test projections which have conflicts in them.
*/
(function() {
"use strict";
const coll = db.projection_conflicts;
coll.drop();
assert.commandWorked(coll.insert({a: {b: 1}}));
function checkProjectionFailsWithCode(proj, codes) {
const collisionErrorCodes = [31250, 31249];
const err = assert.throws(() => coll.find({}, proj).toArray());
assert.contains(err.code, collisionErrorCodes, proj);
const aggErr = assert.throws(() => coll.aggregate({$project: proj}));
assert.contains(err.code, collisionErrorCodes, proj);
}
// Can't test cases like {a: 1, a: "$$REMOVE"} because JS will remove the duplicate keys.
checkProjectionFailsWithCode({"a.b": 1, a: {b: "$$REMOVE"}});
// Inclusion only.
checkProjectionFailsWithCode({"a.b": 1, a: {b: {c: 1}}});
checkProjectionFailsWithCode({a: {b: {c: 1}}, "a.b": 1});
checkProjectionFailsWithCode({a: 1, "a.b": 1});
checkProjectionFailsWithCode({"a.b": 1, a: 1});
checkProjectionFailsWithCode({"a.b": 1, "a.b.c": 1});
// Exclusion only.
checkProjectionFailsWithCode({"a.b": 0, a: {b: {c: 0}}});
checkProjectionFailsWithCode({a: {b: {c: 0}}, "a.b": 0});
checkProjectionFailsWithCode({a: 0, "a.b": 0});
checkProjectionFailsWithCode({"a.b": 0, a: 0});
checkProjectionFailsWithCode({"a.b": 0, "a.b.c": 0});
})();
|