From b4c673a55d93c77297914b4c7407b141a985661a Mon Sep 17 00:00:00 2001 From: Ian Boros Date: Fri, 25 Oct 2019 18:32:57 +0000 Subject: SERVER-44245 Make id_partial_projection.js more robust --- jstests/core/id_partial_projection.js | 21 +++++++++++++-------- 1 file 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}]); })(); -- cgit v1.2.1