summaryrefslogtreecommitdiff
path: root/jstests/core/id_partial_projection.js
blob: 7735e710b9851ec815a4e8ee90d0deb38e102ac0 (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
/**
 * Tests partial inclusion/exclusion of _id.
 * See SERVER-7502 for details.
 */
(function() {
"use strict";

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

// Provide another field, 'sortKey' which we use to ensure the results come in the same order each
// time.
assert.commandWorked(coll.insert({_id: {a: 1, b: 1}, sortKey: 1}));
assert.commandWorked(coll.insert({_id: 3, sortKey: 2}));

function checkResults(projection, expectedResults) {
    assert.eq(coll.find({}, projection).sort({sortKey: 1}).toArray(), expectedResults);
}

checkResults({_id: 1}, [{_id: {a: 1, b: 1}}, {_id: 3}]);
checkResults({"_id.a": 1}, [{_id: {a: 1}}, {}]);
checkResults({"_id.b": 1}, [{_id: {b: 1}}, {}]);

checkResults({"_id.a": 0}, [{_id: {b: 1}, sortKey: 1}, {_id: 3, sortKey: 2}]);
checkResults({_id: 0}, [{sortKey: 1}, {sortKey: 2}]);
})();