【发布时间】:2019-06-10 00:10:37
【问题描述】:
我正在使用以下代码..
// Node.js
router.get('/users/all', authenticate, (req, res) => {
User.find({some query}).select('firstName lastName email').then((users) => {
res.send(users);
});
//Angular Service
let opts = { headers: this.getCommonHeaders(), params: new HttpParams() };
return this.http.get(getUserDataUrl, opts)
.pipe(
map(response => {
// here is the problem
console.log(response.json());
return response.json()
}),
catchError(this.handleErrors)
);
在 opts 标头中我提到了数据类型:
getCommonHeaders() {
return new HttpHeaders({
'Content-Type': 'application/json',
'x-auth': this.getToken()
})
}
在 console.log(response.json()) 中,我在数组对象中只收到电子邮件和 _id。在 res.send(user) 之前在 node.js 上添加相同的 console.log(user) 会显示包含 firstName 和 lastName 的整个数据
然后我将 .lean() 添加到 User 函数中。这允许其余的名字和姓氏出现。如何在不将它们转换为普通对象的情况下获取整个数据?
【问题讨论】:
标签: node.js angular express mongoose mean