static profile = async (req: Request, res: Response) => {
try {
const { username } = req.params;
const account = await userModel
.findOne({ 'shared.username': username })
.exec();
if (account) {
delete account.shared.email; // <======= Why isnt this deleteing email
console.log(account.shared);
res
.status(200)
.send({ shared: account.shared, lastSeen: account.updatedAt });
} else res.status(400).send({ message: 'Server Error' });
} catch (error) {
res.status(400).send({ message: 'Server Error', error });
}
};
console.log(account.shared)显示以下内容
{ language: 'en',
loggedIn: true,
warningMessage: 'verify',
username: 'bill',
email: '[email protected]', // <===== Why is this still here?
fullName: 'Bill',
location: '/contact',
gender: 'male',
avatarId: '338fcdd84627317fa66aa6738346232781fd3c4b.jpg',
country: 'US' }
如果有ID,则>]
console.log(account.shared.email); // undefined
我得到
undefined
,但是如果我在前端使用console.log(response),电子邮件仍然在对象中
静态配置文件=异步(要求:请求,要求:响应)=> {尝试{const {用户名} = req.params; const account = await userModel .findOne({'shared.username':username})...
您可以使用ES6语法将其省略
您声明为const account
,可能是因为将帐户声明为常量会阻止delete
更改对象。尝试改用var account
。