Created
August 18, 2017 09:06
-
-
Save jintao-zero/dee8d8db211f4b1c33abb3722a6932dc to your computer and use it in GitHub Desktop.
python mongo test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import pymongo | |
import pprint | |
print 'this is a python test' | |
mongo_host = 'localhost' | |
#http://api.mongodb.com/python/current/tutorial.html#getting-a-database | |
def test_mongo(): | |
client = pymongo.MongoClient() | |
#db = client.test_database | |
db = client['test_database'] | |
if db is None: | |
print 'db None' | |
else: | |
print 'db not None' | |
#col = db.test_collection | |
col = db['test_collection'] | |
post_id = col.insert_one({'key': 'v'}).inserted_id | |
cursor = col.find({'key':'v'}) | |
for post in cursor: | |
pprint.pprint(post) | |
print (post['key']) | |
#col.drop() | |
if __name__ == '__main__': | |
test_mongo() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment