亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

MongoDB數(shù)據(jù)不存在時插入,已存在時更新
天蓬老師
天蓬老師 2017-04-21 11:15:38
0
3
806

如題,我現(xiàn)在實現(xiàn)的方法是用語句來查詢:

result = db.collection.find_one(xxxx)
if result:
    更新數(shù)據(jù)
else:
    插入數(shù)據(jù)

但是,這種方法效率太低了,不知道有沒有更好的方法?

天蓬老師
天蓬老師

歡迎選擇我的課程,讓我們一起見證您的進步~~

reply all(3)
小葫蘆

MongoDB introduces a special update called upsert. If no document meets the update conditions, a new document will be created based on this condition and the updated document; if a matching document is found, it will be updated normally.

See MongoDB’s documentation for details.

劉奇

upsert:
db.collection.update(xx, xx,true)
Just set the third parameter to true

劉奇

I don’t know if anyone has tested mongodb’s find_one. There is no problem when querying billions of data (tested).

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template