Skip to content

Instantly share code, notes, and snippets.

@dipakyadav
Created June 13, 2018 01:19
Show Gist options
  • Save dipakyadav/237b48cc64b3c5c68ece7f691bd5ab8c to your computer and use it in GitHub Desktop.
Save dipakyadav/237b48cc64b3c5c68ece7f691bd5ab8c to your computer and use it in GitHub Desktop.
Try pymongo
>>> from pymongo import MongoClient
>>> client = MongoClient("mongodb+srv://kay:password@clustername.mongodb.net/test?retryWrites=true")
>>> db = client.test_database
>>> collection = db.test_collection
>>> import datetime
>>> post = {"author": "Mike", "text": "My first blog post!", "tags": ["mongodb", "python", "pymongo"], "date": datetime.datetime.utcnow()}
>>> posts = db.posts
>>> post_id = posts.insert_one(post).inserted_id
>>> post_id
ObjectId('5b2070f157a2f413b5d6c668')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment