shard01:PRIMARY> c = db.oplog.rs.find( { fromMigrate : { $exists : false } } ).addOption( DBQuery.Option.tailable ).addOption(DBQuery.Option.awaitData) { "ts" : Timestamp(1422998530, 1), "h" : NumberLong(0), "v" : 2, "op" : "n", "ns" : "", "o" : { "msg" : "initiating set" } } { "ts" : Timestamp(1422998574, 1), "h" : NumberLong("-6781014703318499311"), "v" : 2, "op" : "i", "ns" : "test.mycollection", "o" : { "_id" : 1, "data" : "hello" } } { "ts" : Timestamp(1422998579, 1), "h" : NumberLong("-217362260421471244"), "v" : 2, "op" : "i", "ns" : "test.mycollection", "o" : { "_id" : 3, "data" : "hello" } } { "ts" : Timestamp(1422998584, 1), "h" : NumberLong("7215322058367374253"), "v" : 2, "op" : "i", "ns" : "test.mycollection", "o" : { "_id" : 5, "data" : "hello" } } shard01:PRIMARY> c.hasNext() true shard01:PRIMARY> c.next() { "ts" : Timestamp(1423049506, 1),
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mongoc_client_t *client = mongoc_client_new ( | |
"mongodb://hostA,hostB/?replicaSet=my_rs"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> # Connect to one standalone, mongos, or replica set member. | |
>>> client = MongoClient(‘mongodb://server’) | |
>>> | |
>>> # Connect to a replica set. | |
>>> client = MongoClient( | |
... ‘mongodb://member1,member2/?replicaSet=my_rs’) | |
>>> | |
>>> # Load-balance among mongoses. | |
>>> client = MongoClient(‘mongodb://mongos1,mongos2’) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> # Two mongoses. | |
>>> client = MongoClient(‘mongodb://mongos1,mongos2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> client = MongoClient(‘mongodb://no-host.com’) | |
>>> client | |
MongoClient('no-host.com', 27017) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> client.db.collection.find_one() | |
AutoReconnect: No servers found yet |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> try: | |
... MongoClient() | |
... print("it's working") | |
... except pymongo.errors.ConnectionFailure: | |
... print("please start mongod") | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> client = MongoClient(serverSelectionTimeoutMS=500) | |
>>> try: | |
... client.admin.command('ping') | |
... print("it's working") | |
... except pymongo.errors.ConnectionFailure: | |
... print("please start mongod") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> db = client.test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> def thread_fn(): | |
... db.read_preference = ReadPreference.SECONDARY |