1// include a and b, exclude other fields
2query.select('a b');
3// Equivalent syntaxes:
4query.select(['a', 'b']);
5query.select({ a: 1, b: 1 });
6
7// exclude c and d, include other fields
8query.select('-c -d');
9
10// Use `+` to override schema-level `select: false` without making the
11// projection inclusive.
12const schema = new Schema({
13 foo: { type: String, select: false },
14 bar: String
15});
16// ...
17query.select('+foo'); // Override foo's `select: false` without excluding `bar`
18
19// or you may use object notation, useful when
20// you have keys already prefixed with a "-"
21query.select({ a: 1, b: 1 });
22query.select({ c: 0, d: 0 });
1Adventure.countDocuments({ type: 'jungle' }, function (err, count) {
2 console.log('there are %d jungle adventures', count);
3});