Hi,
How to disable this option in the mongoexport command line and export from primaries only ?
For MongoDB version 3.2.x and above, mongoexport
allows --readPreference
setting (this is shown in the contents of mongoexport --help
).
However in your case (with MongoDB 3.0.5), you have to connect to the Primary node directly by specifying the Primary’s address in the --host
parameter. You can find out which node is the current Primary by connecting to the replica set and executing db.isMaster().primary
on the mongo
shell.
Please note that exporting from the Primary node may push your working set out of memory and may degrade query performance.
Also, I would recommend to upgrade to the latest version in the 3.0.x series, which is currently 3.0.11, for bugfixes, stability, and performance improvements.
Best regards,
Kevin
Hi,
But in case of sharded collections, how do you connect to the primary nodes of all shards ??
In MongoDB 3.0.x, mongoexport
will dump from each shard’s secondary nodes, and this behavior cannot be changed.
However, in MongoDB 3.2.x, mongoexport
using the --readPreference=primary
setting allows dumping from each shard’s primary. This is also the default behavior of mongoexport
in 3.2.x.
And by the way, what is the —slaveOk option for if it is a default option and cannot be negated ?
This setting is a historical artifact, which is currently being deprecated in MongoDB 3.2.x in favor of a more flexible --readPreference
setting.
You may be able to use mongoexport
version 3.2.x to dump data from MongoDB version 3.0.x, so you can take advantage of the new --readPreference
setting. In my limited testing, it seems to work as expected. However please be sure to test for your use case thoroughly, since you will be mixing versions between the tool and the database engine.
Best regards,
Kevin