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]:
In [22]:
import pprint
In [23]:
pprint.pprint(posts.find_one())
In [ ]: