Mongoose 猫鼬明确包括一个;“隐藏的”;领域
出于安全原因,我已将Mongoose 猫鼬明确包括一个;“隐藏的”;领域,mongoose,Mongoose,出于安全原因,我已将select:false添加到User的密码字段中,以便在默认情况下不会对其进行查询。但是,我想知道在查询用户的登录请求时如何明确地包含它 我的代码现在看起来像这样: User.findOne({email: 'abc'}) .then(user => { ... }).catch(next); 提前谢谢。您可以覆盖mongoose中选择属性文档中提到的查询级别的select:false /** * Sets default select
select:false
添加到User
的密码字段中,以便在默认情况下不会对其进行查询。但是,我想知道在查询用户的登录请求时如何明确地包含它
我的代码现在看起来像这样:
User.findOne({email: 'abc'})
.then(user => {
...
}).catch(next);
提前谢谢。您可以覆盖mongoose中选择属性文档中提到的查询级别的
select:false
/**
* Sets default select() behaviour for this path.
* Set to true if this path should always be included in the results, false
* if it should be excluded by default. This setting can be overridden at
* the query level.
*/
select?: boolean | any;
因此,这可以通过
select(“+password”)
字段来完成,我已经测试了它,它正在工作。您正在使用哪个版本的mongoose?npm的最新版本