In [1]:
from pymongo import MongoClient

In [15]:
client = MongoClient('mongodb://test:passwordhere@mongodb/test') # mongodb = docker magic

In [16]:
db = client.test

In [17]:
collection = db.test_collection

In [18]:
import datetime
post = {"author": "Mike",
    "text": "My first blog post!",
    "tags": ["mongodb", "python", "pymongo"],
    "date": datetime.datetime.utcnow()}

In [19]:
posts = db.posts # creates collection posts

In [20]:
post_id = posts.insert_one(post).inserted_id

In [21]:
post_id


Out[21]:
ObjectId('597b026eb09bc0000fd6442c')

In [22]:
import pprint

In [23]:
pprint.pprint(posts.find_one())


{'_id': ObjectId('597b026eb09bc0000fd6442c'),
 'author': 'Mike',
 'date': datetime.datetime(2017, 7, 28, 9, 22, 53, 566000),
 'tags': ['mongodb', 'python', 'pymongo'],
 'text': 'My first blog post!'}

In [ ]: