2 回答
TA贡献1871条经验 获得超13个赞
Project.find({ uid: req.user._id },{updated_date:0,created_date:0})
.then((project) => {
res.status(200).send({
status: "success",
data: {project},
message: "successful"
});
})
您可以选择隐藏某些字段,例如{updated_date:0,created_date:0}这不会显示updated_date和created_date。但如果你使用 1 它会显示
TA贡献1911条经验 获得超7个赞
您可以简单地使用delete运算符,例如:
let response = {
"status": "success",
"data": {
"project": [
{
"_id": "5e8baea9fe729e4d78855332",
"uid": "5e89c1bd2566a6360cf78097",
"project_name": "Test 00",
"updated_date": "2020-04-06T22:35:21.555Z",
"created_date": "2020-04-06T22:35:21.555Z",
"__v": 0
},
{
"_id": "5e8bb4f5fadc384eb73c6d59",
"uid": "5e89c1bd2566a6360cf78097",
"project_name": "Test 11",
"updated_date": "2020-04-06T23:02:13.498Z",
"created_date": "2020-04-06T23:02:13.498Z",
"__v": 0
}
]
},
"message": "successful"
}
response.data.project.map((p) => {
delete p.created_date;
delete p.updated_date;
});
console.log(response.data.project);
JavaScriptdelete运算符从对象中删除属性;如果不再持有对同一属性的引用,它最终会自动释放。
添加回答
举报