if __name__ == '__main__': db = get_db() my_collection = get_collection(db) post = {"author": "Mike", "text": "My first blog post!", "tags": ["mongodb", "python", "pymongo"], "date": datetime.datetime.utcnow()} # 插入记录 my_collection.insert(post) insert_one_doc(db) # 条件查询 print my_collection.find_one({"x": "10"}) # 查询表中所有的数据 for iii in my_collection.find(): print iii print my_collection.count() my_collection.update({"author": "Mike"}, {"author": "quyang", "text": "My first blog post!", "tags": ["mongodb", "python", "pymongo"], "date": datetime.datetime.utcnow()}) for jjj in my_collection.find(): print jjj get_one_doc(db) get_one_by_id(db) get_many_docs(db) # clear_all_datas(db)