MongoDB - Error: document must have an _id before saving

后端 未结 6 1062
花落未央
花落未央 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:06

    _id is added automatically by MongoDb.

    If you want to keep _id on your data structure be sure to initialize correctly:

    var obj = new UserSchema({ 
        "_id": new ObjectID(), 
        "username": "Bill", 
        "password" : "...." 
    });
    

提交回复
热议问题