Skip to content

Instantly share code, notes, and snippets.

@bowbowbow
Created December 4, 2018 04:02
Show Gist options
  • Save bowbowbow/54120a331ae91ceeb4e1344d0c16bd72 to your computer and use it in GitHub Desktop.
Save bowbowbow/54120a331ae91ceeb4e1344d0c16bd72 to your computer and use it in GitHub Desktop.
import pymongo
_connection = None
def get_db():
global _connection
if not _connection:
_connection = pymongo.MongoClient('mongodb://127.0.0.1')
return _connection['dbname']
if __name__ == '__main__':
db = get_db()
docs = db['collection_name'].find({})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment