MongoDB - Error: document must have an _id before saving

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

    Try below snippet I wanted to name _id as userId you can do without it as well.

    var Schema = mongoose.Schema,
    ObjectId = Schema.ObjectId;
    
    var UserSchema = new Schema({
        username: String,
        password: String
    });
    UserSchema.virtual('userId').get(function(){
        return this._id;
    });

提交回复
热议问题