How to Use Pymongo to Store Data

Last modified by Leon Poon on 2018/12/24 12:27

First, set up a virtualenv.

Make sure that your mongo server is running.

In the virtualenv, install pymongo, then try out this .py file in the virtualenv.

from pymongo import MongoClient
client = MongoClient()
db = client['test-database']
collection = db['test-collection']
print(collection.insert_one({'my_key': 'some value'}))

The printout shows the ID assigned by mongodb to the data you stored. You can now try to look it up.

You can also follow tutorial.

Created by Leon Poon on 2018/12/24 09:47