Skip to content

Document/Understand how to use new mongo read preference feature. #3960

@acinader

Description

@acinader

I want to be able to send some queries to the secondary. My use case is something like: if i know that that a "set of related queries" or a cloud function is just going to read and not write to the db, then I want to send those queries to the secondary.

The thinking being that an app can scale better if read traffic can go to secondaries, cause one can always add more secondaries to handle load.

In looking at the new secondary read feature in parse-server 2.5.0 introduced in #3865 I couldn't really figure out how I could use. I looked at the unit tests and could only see how the read pref was set to SECONDARY in a beforeFind hook, which is by class, not by query, so I'd be setting all queries for that class to the secondary which isn't what i think(?) I want.

It would seem to me that what I'd want to be able to do is something like:

new Parse.Query('Foo').find({ useMasterKey: true, readPreference: 'SECONDARY' }) 

So I figured I'd test that out and here are the changes I needed to make in order to be able to make a Rest Query use the secondary, see #3959

So my questions:

  1. Is my premise somehow flawed as to what I want to use the secondary for?
  2. is there a way to do this already with the 2.5.0 release and I'm just missing it?
  3. does it seem like i'm on the right track?

If it does seem like I am on the right track, I can finish this up and add documentation as well as make any change to the js sdk to support that might be necessary?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions