python簡單操作mongo
阿新 • • 發佈:2019-01-06
from pymongo import MongoClient
client = MongoClient(host='127.0.0.1',port=27017)
collection = client['test']['users']
# 查詢
# data = collection.find()
# print(list(data))
# 新增
# add = collection.insert({'name': 'adley1234', 'pass': '12345abcde'})
# print(add)
# m = collection.update({'user':'xxx'},{'$set': {'pass': 'abc123', 'user': 'aaabbbccc'}})
# m = collection.update_many({'user':'xxx'},{'$set': {'pass': 'abc123', 'user': 'aaabbbccc'}})
# print(m)
# n = collection.remove({'user':'aaabbbccc'})
# print(n)