所以我终于想出了如何使用insert_many的方法。我的代码主要基于电子邮件,但是我确实发现,如果我对相同的电子邮件使用insert_many,则会全部添加它们,我想进行排序检查,以检查数据库中是否已存在电子邮件,然后不要插入它,否则将其插入。
emailList = []
for emails in getEmailFile:
if not db.license.find_one({'email': emails}): #updated
emailList.append({'email': emails.lower().replace("\r","").strip(), "MAC": 0, "key_resets": 0, "raffleItem": []})
db.license.insert_many(emailList)
使用此代码确实可以工作,并且确实可以添加所有集合和元素,但是我想进行排序检查,首先检查在实际插入电子邮件之前是否在数据库中。你们会如何帮助我呢?
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句