我正在尝试在数据库上运行mongoose.findOne,但是得到了意外的结果。我的查询是
const User = mongoose.model('User', {name: String, email: String, passwordHash: String, validation: String, validationCode: String, favorites: Array })
exports.findUser = function findUser(email){
const foundUser = User.findOne({email: email}, function(err, userObj){
if(err){
return err
} else if (userObj){
return userObj
} else{
return null
}
})
return foundUser
}
Run Code Online (Sandbox Code Playgroud)
但是,这将返回以下数据(看似随机?),并且没有我请求的任何数据
Query {
_mongooseOptions: {},
mongooseCollection:
NativeCollection {
collection: null,
opts: { bufferCommands: true, capped: false },
name: 'users',
collectionName: 'users',
conn:
NativeConnection {
base: [Object],
collections: [Object],
models: [Object],
config: [Object],
replica: …Run Code Online (Sandbox Code Playgroud)