File: server6361.js

package info (click to toggle)
mongodb 1%3A3.2.11-2%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 196,404 kB
  • sloc: cpp: 1,412,793; ansic: 504,961; python: 78,522; perl: 5,837; sh: 5,661; java: 4,202; makefile: 1,784; pascal: 617; xml: 176; asm: 128
file content (27 lines) | stat: -rw-r--r-- 779 bytes parent folder | download
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
// SERVER-6361 Disallow exclusions in $project for 2.2

// load the test utilities
load('jstests/aggregation/extras/utils.js');

c = db.c;
c.drop();

c.insert({a: 2, nested: {_id: 2, other: 2}});
assertErrorCode(c, {$project: {a: 0}}, 16406);

// excluding top-level _id is still allowed
res = c.aggregate({$project: {_id: 0, a: 1}});
assert.eq(res.toArray()[0], {a: 2});

// excluding nested _id is not
assertErrorCode(c, {$project: {'nested._id': 0}}, 16406);

// nested _id is not automatically included
res = c.aggregate({$project: {_id: 0, 'nested.other': 1}});
assert.eq(res.toArray()[0], {nested: {other: 2}});

// not including anything is an error
assertErrorCode(c, {$project: {}}, 16403);

// even if you exclude _id
assertErrorCode(c, {$project: {'_id': 0}}, 16403);