Skip to content

Instantly share code, notes, and snippets.

client = MongoClient(
‘mongodb://hostA,hostB/?replicaSet=my_rs’)
my $client = MongoDB::MongoClient->new({
host => "mongodb://hostA,hostB/?replicaSet=my_rs"
});
mongoc_client_t *client = mongoc_client_new (
"mongodb://hostA,hostB/?replicaSet=my_rs");
mongoc_client_pool_t *pool = mongoc_client_pool_new (
"mongodb://hostA,hostB/?replicaSet=my_rs");
mongoc_client_t *client = mongoc_client_pool_pop (pool);
ismaster = {
"setName": "my_rs",
"ismaster": false,
"secondary": true,
"hosts": [
"hostA:27017",
"hostB:27017",
"hostC:27017"]}
db = client.get_database("dbname", read_preference=ReadPreference.SECONDARY)
# Unblocks when a secondary is found.
db.collection.find_one()
ismaster = {
"setName": "my_rs",
"ismaster": true,
"secondary": false,
"hosts": [
"hostA:27017",
"hostB:27017",
"hostC:27017"]}
mongoc_client_t *client = mongoc_client_new (
"mongodb://hostA,hostB/?replicaSet=my_rs"0;
mongoc_client_pool_t *pool = mongoc_client_pool_new (
"mongodb://hostA,hostB/?replicaSet=my_rs");
mongoc_client_t *client = mongoc_client_pool_pop (pool);
ismaster = {
"setName": "my_rs",
"ismaster": false,
"secondary": true,
"primary": "hostC:27017",
"hosts": [
"hostA:27017",
"hostB:27017",
"hostC:27017"]}