时间:2021-07-01 10:21:17 帮助过:65人阅读
以下为简单使用的示例。
#!/usr/bin/python # -*- coding:utf-8 -*- import pymongo class documentManager(object): def __init__(self): pass def connect_mongo(self): client = pymongo.Connection("127.0.0.1",27017) db = client.data_db collection = db.data_collection mydict = {"name":"Lucy", "sex":"female","job":"nurse"} collection.insert(mydict) for i in collection.find({"name":"Lucy"}): print i if __name__ == '__main__': manager = documentManager() manager.connect_mongo()