pymongo之基本操作

#coding:utf8

import pymongo


# 建立連接

mongoclient = pymongo.MongoClient(host='192.168.6.6',port=27017)

# 指定操作數據庫

db = mongoclient['alice']

# 指定操作表(collection)

sheet = db['host']


try:

    # 增加一條

    # sheet.insert({'ip' : '192.168.1.1'})

    # db.host.insert({'ip' : '192.168.1.5', 'port' : 27017})


    # 修改

    # sheet.update({'ip' : '192.168.1.2'},{'$set':{'port':'3306'}},multi=True)


    # 刪除

    # sheet.remove({'ip' : '192.168.1.1'})


    #查詢

    # res = sheet.find({'port' : 27017})

    # for item in res:

    #     print item,type(item)

    pass


except Exception,e:

    print str(e)



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章