MongoDB read-write separation using replica sets to achieve
The secondary node in the replica set is not readable by default. In applications where there is less write-read, the replica sets is used to achieve read-write separation. By specifying Slaveok at the time of connection, or by specifying the secondary in the main library, the pressure of reading is shared by the primary and only the write operation is assumed.
If you access MONGO through the shell, you want to query in secondary. The following error will appear:
Imageset:secondary> Db.fs.files.find ()
Error: {"$err": "Not Master and Slaveok=false", "Code": 13435}
There are two ways to implement a query from a machine:
The first method: Db.getmongo (). Setslaveok ();
The second method: Rs.slaveok ();
The above two lines of command are for the replica to be readable.
But this way has a disadvantage is that the next time through MONGO into the instance, the query will still error, for this can be done by the following ways
VI ~/.mongorc.js
Add a line of Rs.slaveok ();
Each subsequent through the MONGO command access can be queried.
For the operation of switching logs,
>use Admin
> Db.runcommand ({logrotate:1})