diff options
author | Ian Boros <ian.boros@mongodb.com> | 2019-10-25 18:32:57 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-10-25 18:32:57 +0000 |
commit | b4c673a55d93c77297914b4c7407b141a985661a (patch) | |
tree | 8a386eaae0836fe97ee8602e8a6fd46283f4daac | |
parent | 0d84ec739b3e831de70775a5cae20ac1c26c28b1 (diff) | |
download | mongo-b4c673a55d93c77297914b4c7407b141a985661a.tar.gz |
SERVER-44245 Make id_partial_projection.js more robust
-rw-r--r-- | jstests/core/id_partial_projection.js | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/jstests/core/id_partial_projection.js b/jstests/core/id_partial_projection.js index 7affbcfb875..7735e710b98 100644 --- a/jstests/core/id_partial_projection.js +++ b/jstests/core/id_partial_projection.js @@ -8,14 +8,19 @@ const coll = db.id_partial_projection; coll.drop(); -assert.commandWorked(coll.insert({_id: {a: 1, b: 1}, otherField: 1})); -assert.commandWorked(coll.insert({_id: 3, otherField: 2})); +// Provide another field, 'sortKey' which we use to ensure the results come in the same order each +// time. +assert.commandWorked(coll.insert({_id: {a: 1, b: 1}, sortKey: 1})); +assert.commandWorked(coll.insert({_id: 3, sortKey: 2})); -assert.eq(coll.find({}, {"_id": 1}).toArray(), [{_id: {a: 1, b: 1}}, {_id: 3}]); -assert.eq(coll.find({}, {"_id.a": 1}).toArray(), [{_id: {a: 1}}, {}]); -assert.eq(coll.find({}, {"_id.b": 1}).toArray(), [{_id: {b: 1}}, {}]); +function checkResults(projection, expectedResults) { + assert.eq(coll.find({}, projection).sort({sortKey: 1}).toArray(), expectedResults); +} -assert.eq(coll.find({}, {"_id.a": 0}).toArray(), - [{_id: {b: 1}, otherField: 1}, {_id: 3, otherField: 2}]); -assert.eq(coll.find({}, {_id: 0}).toArray(), [{otherField: 1}, {otherField: 2}]); +checkResults({_id: 1}, [{_id: {a: 1, b: 1}}, {_id: 3}]); +checkResults({"_id.a": 1}, [{_id: {a: 1}}, {}]); +checkResults({"_id.b": 1}, [{_id: {b: 1}}, {}]); + +checkResults({"_id.a": 0}, [{_id: {b: 1}, sortKey: 1}, {_id: 3, sortKey: 2}]); +checkResults({_id: 0}, [{sortKey: 1}, {sortKey: 2}]); })(); |