Last modified by Leon Poon on 2021/03/23 13:17

Hide last authors
Leon Poon 5.1 1 First, [[set up a virtualenv>>doc:Computing Newbies.Python Newbies.How to Create a VirtualEnv.WebHome]].
Leon Poon 1.1 2
Leon Poon 4.1 3 Make sure that your [[mongo server is running>>doc:Computing Newbies.How to connect to mongo server.WebHome]].
Leon Poon 1.1 4
Leon Poon 6.1 5 [[In the virtualenv, install pymongo>>doc:Computing Newbies.Python Newbies.How to add libraries to a virtualenv.WebHome]], then try out this .py file [[in the virtualenv>>doc:Computing Newbies.Python Newbies.How to Run a Python Script in a VirtualEnv.WebHome]].
Leon Poon 1.1 6
Leon Poon 2.1 7 {{code language="python"}}
8 from pymongo import MongoClient
Leon Poon 1.1 9 client = MongoClient()
10 db = client['test-database']
11 collection = db['test-collection']
12 print(collection.find_one({'my_key': 'some value'}))
Leon Poon 2.1 13 {{/code}}
Leon Poon 1.1 14
Leon Poon 7.1 15 If you don't have data yet, you can [[store some>>doc:Computing Newbies.Python Newbies.How to Use Pymongo to Store Data.WebHome]].
Leon Poon 1.1 16
17 You can also follow [[tutorial>>url:https://api.mongodb.com/python/current/tutorial.html%7Cthis]].