Dev*_*jee 0 javascript mongoose node.js express
我有一个这样的获取 API
router.get('/exist', async (req, res) => {
try {
const { user: { _id: userId } } = req;
const user = await User.findById(userId);
const profile = await Profile.findById(user.profile, 'role admin');
const admin = await Admin.findOne({ _id: profile.admin })
res.send(admin.role,profile);
} catch (e) {
res.status(500).send();
}
});
Run Code Online (Sandbox Code Playgroud)
在admin
只有一个领域一个要发送回叫的作用。这就是为什么在 res.send() 我写了admin.role
.
所以基本上我想这两个领域发回一起admin.role
和profile
。
直到现在我已经尝试与合并
Object.assign(profile,admin)
Run Code Online (Sandbox Code Playgroud)
&
{...profile,...admin}
Run Code Online (Sandbox Code Playgroud)
这两个都不起作用。
我该怎么做呢?
归档时间: |
|
查看次数: |
43 次 |
最近记录: |