5

I'm very new to mongo and I'd like to direct some queries to the secondaries from the mongo shell.

I've read the docs which say to set the read preference.

Specifically

In the mongo shell, the readPref() cursor method provides access to read preferences.

I've read the docs on the readPref cursor method (here if you're interested: http://docs.mongodb.org/manual/reference/method/cursor.readPref/#cursor.readPref) however I can't make it work.

mongos> cursor.readPref(secondary);
2015-10-15T10:03:47.480+0000 E QUERY    ReferenceError: cursor is not defined
    at (shell):1:1

readPref(secondary);
2015-10-15T10:04:16.224+0000 E QUERY    ReferenceError: secondary is not defined
    at (shell):1:10

mongos> readPref('secondary');
2015-10-15T10:04:37.848+0000 E QUERY    ReferenceError: readPref is not defined
    at (shell):1:1

I've tried every combination of things I can think of, but always get a ReferenceError.

What am I missing / not understanding?

mark
  • 1,769
  • 3
  • 19
  • 38
  • You are reading the wrong manual page, which is about how to set the preference on a returned "cursor". This is the [correct one](http://docs.mongodb.org/manual/reference/method/Mongo.setReadPref/) for a global setting that you seem to want. – Blakes Seven Oct 15 '15 at 10:11
  • Hey thanks! The doc here http://docs.mongodb.org/manual/core/read-preference/ points to that location. I've sent them a note. – mark Oct 15 '15 at 10:15

1 Answers1

2

Blakes Seven just provided the answer (thanks).
You need to go here: http://docs.mongodb.org/manual/reference/method/Mongo.setReadPref/

mark
  • 1,769
  • 3
  • 19
  • 38
  • 1
    Please provide the information that solved the problem in your answer. Links might outdate or change and therfor not work in future. They are great for reference but should not be the main answer. – Mathias Apr 21 '21 at 06:02