Skip to content

Instantly share code, notes, and snippets.

@psihonavt
Created June 23, 2020 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psihonavt/b83d45682613ab8c5703996e15d165fc to your computer and use it in GitHub Desktop.
Save psihonavt/b83d45682613ab8c5703996e15d165fc to your computer and use it in GitHub Desktop.
In [116]: client = newpymongo.MongoClient(["messagesdb1.virtual.ninternal.com:27017"])
In [117]: db = client.get_database("test")
In [118]: db.collection_names()
Out[118]: [u'test']
In [119]: collection = db['test']
In [120]: collection
Out[120]: Collection(Database(MongoClient(host=[u'messagesdb1.virtual.ninternal.com:27017'], document_class=dict, tz_aware=False, connect=True), u'test'), u'test')
In [121]: collection.insert({"v": 5})
Out[121]: ObjectId('5ef25b4596dd1d2b81604368')
In [122]: collection.find_one({"v": 5})
Out[122]: {u'_id': ObjectId('5ef25b4596dd1d2b81604368'), u'v': 5}
In [123]: client_scnd = newpymongo.MongoClient(["messagesdb2.virtual.ninternal.com:27017"])
In [124]: client_scnd.get_database("test")["test"].find({})
Out[124]: <newpymongo.cursor.Cursor at 0x7ff3e4225d50>
In [125]: client_scnd.get_database("test")["test"].find_one({"v": 5})
Out[125]: {u'_id': ObjectId('5ef25b4596dd1d2b81604368'), u'v': 5}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment