1. 程式人生 > >python簡單操作mongo

python簡單操作mongo

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)