search

Home  >  Q&A  >  body text

node.js - mongodb 用findOneAndUpdate更新数据

在使用nodejs操作mongodb时(我用的是monk这个库),使用findOneAndUpdate更新数据时,一条数据第一遍更新是成功的,但第二遍更新不成功,打印错误是:{ lastErrorObject: { updatedExisting: false, n: 0 },
value: null,
ok: 1 }
网上找了很久找不到解决方法,来请教各位大神是怎么回事

PHP中文网PHP中文网2778 days ago760

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 16:06:35

    According to the lastErrorObject you provided:

    1. updatedExisting: false, indicating that the document has not been modified.
    2. n: 0, indicating that the data has been modified to 0

    Normal modification to data will return a value. This value is the modified document

    From what you said, when updating the data, the corresponding document was not found according to the filter conditions, so the updte was not successful.

    For reference.

    Love MongoDB! Have Fun!

    reply
    0
  • Cancelreply