Aggregation query and read preference

62 views
Skip to first unread message

Bhupen Sinha

unread,
Jul 12, 2017, 8:00:22 AM7/12/17
to mongodb-dev
Hello All

like we can indicate the read preference with a normal FIND() query, can we do the same with an aggregation query? I tried but failed

db.marks.find({marks:{$gte:50}}).comment(‘spref’).readPref(‘secondaryPreferred’) .. this works


but 

the following does not work ... Any solution pls?

 db.zipcode.aggregate ( [
    { $group: { _id: { state: "$state", city: "$city" }, pop: { $sum: "$pop" } } },
    { $group: { _id: "$_id.state", avgCityPop: { $avg: "$pop" } } },
    { $out : “zipout" } 

 ] ).readPref(‘secondary’)

thanks!

Asya Kamsky

unread,
Jul 13, 2017, 6:30:44 PM7/13/17
to mongo...@googlegroups.com
You can set your read preference to secondary (i.e. in the shell: db.getMongo().setReadPref('secondary’)) but I’m afraid this aggregation cannot run on secondary since it has “$out” stage and therefore it *must* be run on the primary.

Asya


--
You received this message because you are subscribed to the Google Groups "mongodb-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-dev+unsubscribe@googlegroups.com.
To post to this group, send email to mongo...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-dev.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-dev/c1403f2d-c2b6-4a51-b258-6b38f5028f33%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Asya Kamsky
Lead Product Manager
MongoDB
Download MongoDB - mongodb.org/downloads
We're Hiring! - https://www.mongodb.com/careers
Reply all
Reply to author
Forward
0 new messages