how to connect mongodb primar node in replica set by mongo shell

14 views
Skip to first unread message

amazo...@gmail.com

unread,
Jun 30, 2015, 9:47:04 AM6/30/15
to mongod...@googlegroups.com

here is javascript which will be called by mongo shell "mongo --nodb --shell test.js",I found mongo shell random connect the 1 of the 3 node,is there any way to always  connect to primary node?any parameter add in followng conn str,thanks.

conn = new Mongo("replica/mongo01,mongo02,mongo03");
db = conn.getDB("db1");
do sth.....

Asya Kamsky

unread,
Jun 30, 2015, 12:37:32 PM6/30/15
to mongodb-user
You can just connect directly to the cluster when invoking the shell via:

mongo --host replica/mongo01,mongo02,mongo03 test.js

and it will connect to the primary and run whatever is in test.js

Asya
> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user"
> group.
>
> For other MongoDB technical support options, see:
> http://www.mongodb.org/about/support/.
> ---
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mongodb-user...@googlegroups.com.
> To post to this group, send email to mongod...@googlegroups.com.
> Visit this group at http://groups.google.com/group/mongodb-user.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mongodb-user/c679a146-e1a6-4263-aa32-d5eb3cc5b9d8%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages