[SERVER-10677] Execute aggregation framework on secondary node Created: 04/Sep/13  Updated: 10/Dec/14  Resolved: 09/Sep/13

Status: Closed
Project: Core Server
Component/s: Aggregation Framework, Internal Client
Affects Version/s: 2.4.6
Fix Version/s: None

Type: Question Priority: Minor - P4
Reporter: Dmitry Assignee: Unassigned
Resolution: Done Votes: 0
Labels: aggregate, c++, mongod, mongos
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Linux Ubuntu 12.04 single shard server with 4 nodes in one replicaset 2.4.6


Participants:

 Description   

Hello.

In C++ i tried execute aggregation framework like in example with readPreference :

conn->runCommand( "goods", BSON( "aggregate" << "events" << "pipeline" << pipeline<<"$readPreference"<<BSON("mode"<<"secondaryPreferred")), res);

Client connected to monogos with one single shard with four nodes in replicaset. Command always execute on primary node.

I dont understand, how execute framework on secondary node.
Is it possible?

Thank you.



 Comments   
Comment by Dmitry [ 05/Sep/13 ]

Thank you. Works for me.

If add to cmdCommand $queryOptions: { $readPreference:

{ mode: "secondaryPreferred" }

} } works too.

Comment by Randolph Tan [ 04/Sep/13 ]

Hi,

Currently, there is no helper method for the C++ driver for setting read preference for commands. As a work around, can you try doing this instead?

Query cmd(BSON("aggregate" << "events" << "pipeline" << pipeline));
cmd.readPref(mongo::ReadPreference_SecondaryPreferred, BSONArray());
BSONObj result = conn->findOne("goods.$cmd", cmd);

Generated at Thu Feb 08 03:23:46 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.