mongoose

Mongoose __v property - hide?


Mongoose adds a '__v' property into Schema's for versioning - is it possible to disable this globally or globally hide it from all queries?


Solution

  • You can disable the "__v" attribute in your Schema definitions by setting the versionKey option to false. For example:

    var widgetSchema = new Schema({ ... attributes ... }, { versionKey: false });
    

    I don't think you can globally disable them, but can only do it per Schema. You can read more about Schema's options here. You might also find the Schema set method helpful.