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
|
// Test $type expression with non-existent field in the document.
(function() {
"use strict";
const coll = db.type_operator_on_missing_values;
coll.drop();
const documentList = [
{_id: 0},
{_id: 1, b: 123},
];
assert.commandWorked(coll.insert(documentList));
const bsonTypes = [
"double", "string", "object", "array", "binData",
"undefined", "objectId", "bool", "date", "null",
"regex", "dbPointer", "javascript", "symbol", "javascriptWithScope",
"int", "timestamp", "long", "decimal", "minKey",
"maxKey",
];
for (const type of bsonTypes) {
let results = coll.find({a: {$type: type}}).sort({_id: 1}).toArray();
assert.eq(results, []);
results = coll.find({a: {$not: {$type: type}}}).sort({_id: 1}).toArray();
assert.eq(results, documentList);
}
}());
|