summaryrefslogtreecommitdiff
path: root/jstests/core/expr_valid_positions.js
blob: cd3ae2bf917532bef27031ffc4677eda9f897e45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Verify that $expr can be used in the top-level position, but not in subdocuments.

(function() {
"use strict";

const coll = db.expr_valid_positions;

// Works at the BSON root level.
assert.eq(0, coll.find({$expr: {$eq: ["$foo", "$bar"]}}).itcount());

// Works inside a $or.
assert.eq(0, coll.find({$or: [{$expr: {$eq: ["$foo", "$bar"]}}, {b: {$gt: 3}}]}).itcount());

// Fails inside an elemMatch.
assert.throws(function() {
    coll.find({a: {$elemMatch: {$expr: {$eq: ["$foo", "$bar"]}}}}).itcount();
});

// Fails inside an _internalSchemaObjectMatch.
assert.throws(function() {
    coll.find({a: {$_internalSchemaObjectMatch: {$expr: {$eq: ["$foo", "$bar"]}}}}).itcount();
});
}());