Mongoose.js默认情况下除查询结果中的_id和__v外

WHI*_*LOR 8 mongoose

我可以从查询结果中的字段除外声明它:

field:{type:'string',select:false}

但是有可能用_id和__v字段做到这一点吗?我试过了

_id:{select:false}

但它似乎无法奏效

Joh*_*yHK 16

只要您还在type架构定义中包含字段,就可以执行此操作:

_id: {type: mongoose.Schema.ObjectId, select: false},
__v: {type: Number, select: false},
Run Code Online (Sandbox Code Playgroud)

但是,这将阻止Mongoose能够在a上找到你的模型实例(并更新它__v),save除非你明确地在你的中添加了这些字段find.因此,请确保您知道自己在做什么.