简体   繁体   中英

How can I use rs.slaveOK() on mongo shell?

I have checked the official document many times, it dose has the rs.slaveOK() function there and also the shell-help document.

外壳帮助文档

I can't use rs.slaveOK() even if the function really exist.(Error occur)

That is so weird. Why is that?

The shell try to indicate me that rs.slaveOK() is not a function when I type it.

Be careful! MongoDB functions are case sensitive:

rs.slaveOK() is not a function

rs.slaveOk() is the function you are looking for.

You would use rs.slaveOk() when your Mongodb is set up as a replicaset, and you wish to query one of the secondary nodes, rather than the primary. slaveOk is instructing the shell that its ok to return results from a secondary (rather than a primary) even though the results may not be entirely consistent with the primary.

I could be wrong, but it doesn't look like you are connected to a Mongodb which is configured as a replicaset, and if you are then I'm guessing that you are not connected to a secondary. Therefore the instruction to query a secondary makes no sense.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM