在以下插入中,我想根据sUserRole
结果为count
分配值。现在,在密钥userRole
下插入文档后,MongoDB中的文件为null
。我做错了什么?
user.signupUser = (jUserData, fCallback) => {
var sUserRole;
global.db.collection('users').count((err, count) => {
if (err) throw err;
else if (count === 0) {
sUserRole = "admin";
}
sUserRole = "user";
})
var jUser = {
userName: jUserData.txtUserEmailorPhoneNumber,
userRole: sUserRole,
firstName: jUserData.txtUserFirstName,
lastName: jUserData.txtUserLastName,
password: jUserData.txtUserPassword,
image: global.sSignupUserImagePath
}
global.db.collection('users').insertOne(jUser, (err, jResult) => {
if (err) {
var jError = {
"status": "error",
"message": "ERROR -> signupUser -> user.js -> 001"
}
return fCallback(false, jError)
}
var jOk = {
"status": "ok",
"message": "user.js -> user saved -> 000"
}
return fCallback(false, jOk)
})
}