pymongo 在 pycharm 中的使用

在pycharm 中使用 pymongo 入门
from pymongo import MongoClient
import datetime
client = MongoClient() # connect default MongoDB
db=client.test_database
# create one document

post1 = {"author": "ZH",
        "text": "My first blog post!",
        "tags": ["mongodb", "python", "pymongo"],
        "date": datetime.datetime.utcnow()}
post ={ "author": "CX",
        "text": "My second blog post!",
        "tags": ["python", "pymongo"],
        "date": datetime.datetime.utcnow()}
# insert documents
posts = db.posts
postID = posts.insert_one(post1).inserted_id
print(postID) # one string would be returned, that is the document id
posts.insert_one(post)

# query data with function find_one 
import pprint
print("Records in current document:")
pprint.pprint(posts.find_one({"author":"CX"}))
 
 

更多内容更可以参考:   http://api.mongodb.com/python/current/tutorial.html#documents 



猜你喜欢

转载自blog.csdn.net/chenxin0215/article/details/80585448
今日推荐