I can successfully get all the users but what I need is to get the logged in user's detail. .find()
find everyone in the DB is there a specific func to get the current user? I thought User.getUser()
mongodb func would identify the currently logged in user but apparently not.
我可以成功获得所有用户,但我需要的是获取登录用户的详细信息。 .find()发现数据库中的每个人都有特定的函数来获取当前用户吗?我以为User.getUser()mongodb func会识别当前登录的用户,但显然不是。
I'm creating a user profile page for this logged in user.
我正在为此登录用户创建用户个人资料页面。
Login
module.exports.login = function (req, res){
User.find(req.body, function (err, results){
if (err) throw err;
var jsonToken = {
username: req.body.username,
expiry: new Date().toISOString()
}
var encryptedData = btoa(JSON.stringify(jsonToken));
console.log(encryptedData);
if (results && results.length === 1){
res.json(encryptedData);
}
})
}
Get user
module.exports.getuser = function (req, res) {
console.log('get current user detail');
User.find(req.body, function(err, result) {
if(err) throw err;
if(result) {
console.log(result);
res.json(result);
}
})
}
Angular Ctrl
var getUser = function() {
signupService.getUserDetail()
.then(function(response) {
console.log(response.data);
});
}
1 个解决方案
#1
0
The db.runCommand
function and connectionStatus
command might be what you're looking for.
db.runCommand函数和connectionStatus命令可能正是您要查找的内容。
-
connectionStatus
- Returns information about the current connection, specifically the state of authenticated users and their available permissions.
connectionStatus - 返回有关当前连接的信息,特别是经过身份验证的用户的状态及其可用权限。
MongoDB Shell Example
> db.runCommand({connectionStatus: 1})
{
"authInfo" : {
"authenticatedUsers" : [
{
"user" : "myUser",
"db" : "myDB"
}
],
"authenticatedUserRoles" : [
{
"role" : "dbAdmin",
"db" : "myDB"
},
{
"role" : "readWrite",
"db" : "myDB"
}
]
},
"ok" : 1
}
#1
0
The db.runCommand
function and connectionStatus
command might be what you're looking for.
db.runCommand函数和connectionStatus命令可能正是您要查找的内容。
-
connectionStatus
- Returns information about the current connection, specifically the state of authenticated users and their available permissions.
connectionStatus - 返回有关当前连接的信息,特别是经过身份验证的用户的状态及其可用权限。
MongoDB Shell Example
> db.runCommand({connectionStatus: 1})
{
"authInfo" : {
"authenticatedUsers" : [
{
"user" : "myUser",
"db" : "myDB"
}
],
"authenticatedUserRoles" : [
{
"role" : "dbAdmin",
"db" : "myDB"
},
{
"role" : "readWrite",
"db" : "myDB"
}
]
},
"ok" : 1
}