Skip to content

Model.aggregate(..).read('secondary') does not return an error if no secondary nodes available #2606

@cblanc

Description

@cblanc

I'm running a single node replica (version 2.6.4) set in my development setup using Mongoose version 3.8.20.

My aggregate queries look something like this:

MyModel.aggregate({ $match: { createdAt: { $gte: start, $lte: end } } }, { $group: { _id: { day: {$dayOfMonth: "$createdAt"}, month: {$month: "$createdAt"}, year: {$year: "$createdAt"} }, count: {$sum: 1} } }) .read("secondary") .exec(callback); 

Ordinarily my read preference is set to "secondaryPreferred" because I'm running a single node for testing and development while there's a replica set in production. However I swapped read preference to "secondary" just to reassure myself that my query was sensitive to read() and contrary to what I expected, the query ran just fine. I did not receive any error to my callback.

According to the documentation for Query#read, querying with secondary should return an error if no secondaries are available. Is the behaviour for Aggregate#read meant to differ?

Additional Info:

  • My schema read preference is left as default ("primary") - changing it does not make a difference
  • The query runs fine with using any setting: E.g. nearest, primaryPreferred, etc
  • The query fails as expected if I pass read some random string

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions