user upsert
This commit is contained in:
parent
bb16fadb40
commit
a1f523f07e
Binary file not shown.
@ -22,7 +22,9 @@ class Base:
|
|||||||
|
|
||||||
user = self.user()
|
user = self.user()
|
||||||
|
|
||||||
store.insert_one({
|
store.replace_one({
|
||||||
|
"id": user.id
|
||||||
|
}, {
|
||||||
"id": user.id,
|
"id": user.id,
|
||||||
"shortId": user.shortId,
|
"shortId": user.shortId,
|
||||||
"nickname": user.nickname,
|
"nickname": user.nickname,
|
||||||
@ -32,9 +34,10 @@ class Base:
|
|||||||
"followingCount": user.followInfo.followingCount,
|
"followingCount": user.followInfo.followingCount,
|
||||||
"followerCount": user.followInfo.followerCount
|
"followerCount": user.followInfo.followerCount
|
||||||
}
|
}
|
||||||
})
|
}, upsert=True)
|
||||||
|
|
||||||
store.set_collection(self.instance.common.method)
|
store.set_collection(self.instance.common.method)
|
||||||
|
|
||||||
store.insert_one({
|
store.insert_one({
|
||||||
"msgId": self.instance.common.msgId,
|
"msgId": self.instance.common.msgId,
|
||||||
"roomId": self.instance.common.roomId,
|
"roomId": self.instance.common.roomId,
|
||||||
@ -42,7 +45,7 @@ class Base:
|
|||||||
'content': self.format_content()
|
'content': self.format_content()
|
||||||
})
|
})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(self.instance.common.method + 'persists error')
|
print(self.instance.common.method + ' persists error')
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
Binary file not shown.
@ -10,6 +10,9 @@ class MongoStore:
|
|||||||
def set_collection(self, collection):
|
def set_collection(self, collection):
|
||||||
self.collection = self.db[collection]
|
self.collection = self.db[collection]
|
||||||
|
|
||||||
|
def replace_one(self, condition, data, upsert=True):
|
||||||
|
return self.collection.replace_one(condition, data, upsert=upsert)
|
||||||
|
|
||||||
def insert_one(self, data):
|
def insert_one(self, data):
|
||||||
return self.collection.insert_one(data)
|
return self.collection.insert_one(data)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user