|
The drivers team currently plans to update read preference behavior for $out, $merge, and mapReduce as part of their 4.6 compatible releases rather than their 4.4 compatible releases. They advise that we do the same for the shell. Therefore, I am returning this ticket to the backlog.
Note that in addition to the behavior described by mihai.andrei above for connections to individual nodes, the read preference is not respected for $out/$merge/mapReduce operations run against replica set node connections. Consider the following short repro script for this behavior:
let rst = new ReplSetTest({nodes: 2});
|
rst.startSet();
|
rst.initiate();
|
|
// Enable log level 1 on both primary and secondary.
|
rst.getPrimary().getDB("test").setLogLevel(1);
|
rst.getSecondary().getDB("test").setLogLevel(1);
|
|
assert.commandWorked(rst.getPrimary().getDB("test").source.insert({_id: 1}));
|
assert.commandWorked(rst.getPrimary().getDB("test").source.insert({_id: 2}));
|
|
let replSetConn = new Mongo(rst.getURL());
|
replSetConn.setReadPref("secondary");
|
const testDb = replSetConn.getDB("test");
|
|
// This operation gets targeted to the primary, despite the secondary read preference set on the connection.
|
assert.eq(0, testDb.source.aggregate([{$out: "target"}]).itcount());
|
|
// This operation gets sent to the secondary as expected.
|
assert.eq(2, testDb.source.aggregate([{$addFields: {newField: 1}}]).itcount());
|
|
rst.stopSet();
|
Examining the logs will show that the $addFields operation is sent to the replica set secondary node due to the "secondary" read preference. However, for the $out operation the read preference is ignored and the operation is send to the primary.
CC divjot.arora behackett
|