MongoDB - Error: document must have an _id before saving

后端 未结 6 1022
花落未央
花落未央 2020-12-30 03:48

I\'ve been struggling so much with this project. I am following a tutorial that is out of date in some areas, for instance their version of Jquery used a totally different f

6条回答
  •  一生所求
    2020-12-30 04:08

    Its pretty simple:

    1. If you have declared _id field explicitly in schema, you must initialize it explicitly
    2. If you have not declared it in schema, MongoDB will declare and initialize it.

    What you can't do, is to have it in the schema but not initialize it. It will throw the error you are talking about

提交回复
热议问题