Mongoose.js,除了_id&默认情况下来自查询结果的__v [英] Mongoose.js except _id & __v from query result by default

查看:166
本文介绍了Mongoose.js,除了_id&默认情况下来自查询结果的__v的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了查询结果中的字段,我可以像这样声明该字段:

I can except a field from query results declaring it like:

字段:{type:'string',select:false}

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

但是可以通过_id和__v字段来做到这一点吗? 我尝试过

Is but it possible to do that with _id and __v field? I tried

_id:{select:假}

_id: {select: false}

但是似乎不起作用

推荐答案

您可以执行此操作,只要您还在模式定义中包括字段的type:

You can do this as long as you also include the type of the field in the schema definitions:

_id: {type: mongoose.Schema.ObjectId, select: false},
__v: {type: Number, select: false},

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

However, that's going to prevent Mongoose from being able to find your model instance (and update its __v) on a save unless you explicitly include those fields in your find. So make sure you know what you're doing.

这篇关于Mongoose.js,除了_id&默认情况下来自查询结果的__v的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆