Wiki source code of How to Use Pymongo and Search for Data
Hide last authors
| author | version | line-number | content |
|---|---|---|---|
| |
1.1 | 1 | First, [[set up a virtualenv>>url:https://wiki.codepowered.com/wiki/How_to_Create_a_VirtualEnv]]. |
| 2 | |||
| 3 | Make sure that your [[mongo server is running>>url:https://wiki.codepowered.com/wiki/How_to_connect_to_mongo_server]]. | ||
| 4 | |||
| 5 | [[In the virtualenv, install pymongo>>url:https://wiki.codepowered.com/wiki/How_to_add_libraries_to_a_virtualenv]], then try out this .py file [[in the virtualenv>>url:https://wiki.codepowered.com/wiki/How_to_Run_a_Python_Script_in_a_VirtualEnv]]. | ||
| 6 | |||
| 7 | {{{from pymongo import MongoClient | ||
| 8 | client = MongoClient() | ||
| 9 | db = client['test-database'] | ||
| 10 | collection = db['test-collection'] | ||
| 11 | print(collection.find_one({'my_key': 'some value'})) | ||
| 12 | }}} | ||
| 13 | |||
| 14 | If you don't have data yet, you can [[store some>>url:https://wiki.codepowered.com/wiki/How_to_Use_Pymongo_to_Store_Data]]. | ||
| 15 | |||
| 16 | You can also follow [[tutorial>>url:https://api.mongodb.com/python/current/tutorial.html%7Cthis]]. |