How to do a mongoexport without the slaveOk option ?

128 views
Skip to first unread message

rejoc

unread,
Apr 12, 2016, 9:10:17 AM4/12/16
to mongodb-user
Current documentation specifies that the --slaveOk option is the default for mongoexport. 
So by default the export is done from the secondaries.

How to disable this option in the mongoexport command line and export from primaries only ?

rejoc

unread,
Apr 12, 2016, 11:22:03 AM4/12/16
to mongodb-user
(mongodb 3.0.5)

Kevin Adistambha

unread,
Apr 18, 2016, 7:27:38 PM4/18/16
to mongodb-user

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

rejoc

unread,
Apr 19, 2016, 4:30:47 AM4/19/16
to mongodb-user
Thanks Kevin,

But in case of sharded collections, how do you connect to the primary nodes of all shards ??

And by the way, what is the --slaveOk option for if it is a default option and cannot be negated ?

Kevin Adistambha

unread,
Apr 21, 2016, 11:34:03 PM4/21/16
to mongodb-user

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

Reply all
Reply to author
Forward
0 new messages