Remove the extra underscores in the mongodb database documents of the mongoose operation, the underscore v is the __v field

When creating a collection, the default __v field will be added to indicate the version, as shown in the following figure

If you want to not display the __v field in the database, you can remove this field by setting versionKey: false when defining the schema rule:

var userSchema = new mongoose.Schema({
    username: {
        type:String,
        required:true,
      },
    password: {
            type:String,
            required:true,
            select:false
          },
       
    }, {versionKey:false})

 If you keep this field in the database, but you don’t want to return the __v field when querying, you can filter out this field in the returned results by setting {__v: 0}

UserModel.findOne({username, password}, {__v: 0}, function (err, user)
{
//处理逻辑
}

 

Guess you like

Origin blog.csdn.net/a1059526327/article/details/106893186