diff options
author | Ian Boros <ian.boros@mongodb.com> | 2019-11-14 21:32:37 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-11-14 21:32:37 +0000 |
commit | cdc44d95e169da75093f25c324aa9670e72743e8 (patch) | |
tree | a1e8edd7f13465513b0942d309c63221250b0132 /jstests/core/positional_projection_multiple_array_fields.js | |
parent | 3f4312f26e1667826db51a0d2834eb417bb5de2d (diff) | |
download | mongo-cdc44d95e169da75093f25c324aa9670e72743e8.tar.gz |
SERVER-15164 test that positional operator and $slice can be used in the same projection
Diffstat (limited to 'jstests/core/positional_projection_multiple_array_fields.js')
-rw-r--r-- | jstests/core/positional_projection_multiple_array_fields.js | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/jstests/core/positional_projection_multiple_array_fields.js b/jstests/core/positional_projection_multiple_array_fields.js index 149eff22e7e..267056f43e9 100644 --- a/jstests/core/positional_projection_multiple_array_fields.js +++ b/jstests/core/positional_projection_multiple_array_fields.js @@ -15,10 +15,18 @@ coll.drop(); assert.commandWorked(coll.insert({_id: 0, a: [1, 2, 3], z: [11, 12, 13]})); assert.eq(coll.find({z: 13}, {a: {$slice: 2}}).toArray(), [{_id: 0, a: [1, 2], z: [11, 12, 13]}]); assert.eq(coll.find({z: 13}, {a: {$slice: 2}, "z.$": 1}).toArray(), [{_id: 0, a: [1, 2], z: [13]}]); +coll.drop(); + +coll.insert({_id: 0, importing: [{foo: "a"}, {foo: "b"}], "jobs": [{num: 1}, {num: 2}, {num: 3}]}); +assert.eq(coll.find({"importing.foo": "b"}, {jobs: {'$slice': 2}, 'importing.$': 1}).toArray(), + [{_id: 0, importing: [{foo: "b"}], jobs: [{num: 1}, {num: 2}]}]); +assert.eq(coll.find({"importing.foo": "b"}, {jobs: {'$slice': -1}, 'importing.$': 1}).toArray(), + [{_id: 0, importing: [{foo: "b"}], jobs: [{num: 3}]}]); coll.drop(); assert.commandWorked(coll.insert({_id: 1, a: [{b: 1, c: 2}, {b: 3, c: 4}], z: [11, 12, 13]})); assert.eq(coll.find({z: 12}, {"a.b": 1}).toArray(), [{_id: 1, a: [{"b": 1}, {"b": 3}]}]); + // The positional projection on 'z' which limits it to one element shouldn't be applied to 'a' as // well. assert.eq(coll.find({z: 12}, {"a.b": 1, "z.$": 1}).toArray(), |