我正在尝试使用mongoose找到现有用户我的查询是
UserAccount.find(variables, function (error, success) {
if (error) {
response.send({status: false});
} else {
console.log(success);
}
});
如果用户存在意味着它返回以下数组。
[ model {
'$__':
InternalCache {
strictMode: true,
selected: [Object],
shardval: undefined,
saveError: undefined,
validationError: undefined,
adhocPaths: undefined,
removing: undefined,
inserting: undefined,
saving: undefined,
version: undefined,
getters: {},
_id: 5c98e64f2106e94022532c9f,
populate: undefined,
populated: undefined,
wasPopulated: false,
scope: undefined,
activePaths: [StateMachine],
pathsToScopes: {},
session: null,
ownerDocument: undefined,
fullPath: undefined,
emitter: [EventEmitter],
'$options': [Object] },
isNew: false,
errors: undefined,
_doc:
{ isActive: true,
_id: 5c98e64f2106e94022532c9f,
userName: '[email protected]',
password:
'$2a$05$vpowA76cB3T/4eHGbQPqd.F/iIebX7SXKPZA2k1wcmlSIDks0q852',
userCategory: 'buyer',
createdDate: 2019-03-20T14:31:43.250Z,
updatedDate: 2019-03-20T14:31:43.250Z,
__v: 0 },
'$init': true } ]
我不知道造成这个问题的原因是什么?直到昨天它才返回用户数据,但这对我来说太奇怪了。如何解决这个问题?有人可以帮我解决这个问题吗?谢谢。
我也遇到了同样的问题,问题是如果你使用最新版本的mongo与较旧的猫鼬,这可以通过安装较新的mongoose版本并运行mongoose find()来解决,这将解决你的问题。
您最初获得的额外属性是由于结果是模型实例的集合,其中附带了在普通对象上不可用的其他属性和方法。你可以传递{lean: true}
作为一个选项获取普通对象,而不需要所有这些额外的属性和方法。
UserAccount.find(variables, {lean: true}, function (error, success) {
if (error) {
response.send({status: false});
} else {
console.log(success);
}
});