import pymongo
client = pymongo.MongoClient("mongodb://192.168.31.151:27017")
[i for i in client["db"].list_collections()]
client["db"]["test"].create_index([("serial", pymongo.ASCENDING)], unique=True)
[i for i in client["db"].list_collections()]
c = client["db"]["test"]
c.insert_one({
"serial": 1,
"a": 2
})
[i for i in c.find()]
[i for i in c.find({}, {"_id": 0})]
c.update_one({"serial": 2}, {
"$set": {
"serial": 2,
"b": 3
}
}, upsert=True)
[i for i in c.find({}, {"_id": 0})]
c.update_one({"serial": 2}, {
"$set": {
"serial": 2,
"b": 4
}
}, upsert=True)
[i for i in c.find({}, {"_id": 0})]