def _upsertData(db, clct, data):
'''Internal: Upsert json, text or binary data to db.clct.
json and binary files need a little pre-processing by the calling
function(s), which then call this internal function.
'''
try:
res = clct.replace_one(
{'name': data['name']},
data,
upsert=True) # Create it if it doesn't exist.
except Exception as e:
e.args += (' '.join([
'Collection: %s;'%(clct.name),
'data: %s;'%(str(data)),
'type(data) should be dict: %s'%(type(data)),
'%s collection validation rules:'%(clct.name),
pformat(clct.options()) ]),)
raise
return ('%s to %s.%s, modified: %s, upserted: %d'%(
data['name'], db.name, clct.name,
res.modified_count,
1 if res.upserted_id else 0
)).strip()
评论列表
文章目录