无法从服务模型返回用户

时间:2019-01-23 06:50:07

标签: javascript reactjs mongodb mongoose

我需要将用户从我的服务模型返回到控制器模型,但是我无法做到这一点,有人可以帮助我吗?

async function create(userParam) {


if (await User.findOne({ username: userParam.username })) {
    throw 'Username "' + userParam.username + '" is already taken';
}

const user = new User(userParam);
console.log("User", userParam , user )
// hash password
if (userParam.password) {
    user.hash = bcrypt.hashSync(userParam.password, 10);
}

// return user from here
await user.save();
} 

1 个答案:

答案 0 :(得分:0)

尝试这个`

user.save().then(item =>{
 return item ;
}

`