我一直想知道,将updatemongodb{upsert:true}选项一起使用,是否可以将upsertedCountmodifiedCount都设置为0?

我知道upsertedCount是指创建的文档,而modifiedCount是指更新的文档。

因此,使用upsert时,我无法找到两个都等于0的情况。

我错了吗?

先谢谢您的帮助。

最佳答案

我认为您的假设是正确的。
Upsert基本上意味着如果找不到文档,则创建一个新文档。
因此,如果在进行更新时将其设置为true,则该文档将存在并且将被修改(将modifiedCount设置为1)或该文档不存在(将upsertCount设置为1)

09-25 17:18