Files
mongo/jstests/aggregation/parsing/agg_read_pref.js
Zac 591928c619 SERVER-108478 JS formatted by prettier and remove clang-format (#39656)
GitOrigin-RevId: 6c8f6aded47f260aa4f7c231b17dae3302cb1e04
2025-08-21 17:27:09 +00:00

20 lines
664 B
JavaScript

// SERVER-7768 aggregate cmd shouldn't fail when $readPreference is specified.
//
// @tags: [
// # This test sets a read preference itself and does not expect it to be overridden.
// assumes_read_preference_unchanged,
// ]
const collection = db[jsTestName()];
collection.drop();
assert.commandWorked(collection.insert({foo: 1}));
// Can't use aggregate helper here because we need to add $readPreference flag.
let res = db.runCommand({
aggregate: collection.getName(),
pipeline: [{$project: {_id: false, foo: true}}],
$readPreference: {mode: "primary"},
cursor: {},
});
assert.commandWorked(res);
assert.eq(res.cursor.firstBatch, [{foo: 1}]);