Files
mongo/jstests/libs/find_cmd_util.js
kmznam d746002ff1 SERVER-91719 Rewrite tests to not use cursor.firstBatch to evaluate results (#25346)
GitOrigin-RevId: 80bfe0fc45720a12122962658c574b208580d346
2024-07-29 14:22:30 +00:00

21 lines
681 B
JavaScript

/**
* Given a command and batch size, runs the command and enough getMores to exhaust the cursor,
* returning all of the results.
*/
export function exhaustFindCursorAndReturnResults(db, cmd) {
const namespace = cmd.find;
const initialResult = assert.commandWorked(db.runCommand(cmd));
let cursor = initialResult.cursor;
let allResults = cursor.firstBatch;
while (cursor.id != 0) {
const getMore = {getMore: cursor.id, collection: namespace};
const getMoreResult = assert.commandWorked(db.runCommand(getMore));
cursor = getMoreResult.cursor;
allResults = allResults.concat(cursor.nextBatch);
}
return allResults;
}