我为用户编写了一个API,用于存储他/她的头像数据,用户信息已将其嵌套在另一个文档中。 这是我的模特。
const UserSchema = new mongoose.Schema({
_id: String,
email: {
type: String,
lowercase: true,
unique: true,
required: true
},
password: {
type: String,
required: true
},
passwordResetToken: String,
passwordResetExpires: Date,
role: {
type: String,
enum: ['creator', 'admin'],
default: 'creator'
},
tokens: Array,
profile: {
name: String,
gender: String,
location: String,
picture: {
data: Buffer, contentType: String
}
}
}, {
timestamps: true
});
我的GET
方法是。
exports.getUsers = (req, res) => {
User.find({}).lean().exec(function (err,docs) {
return res.json(docs);
})
}
在邮递员查询数据时,我得到了这个
[
{
"_id": "59d665c3acbde702b47d3987",
"updatedAt": "2017-10-07T17:23:00.498Z",
"createdAt": "2017-10-05T17:02:59.526Z",
"email": "me@mail.com",
"password": "$2a$05$z1mRUWqqUfM8wKMU/y9/sOLssAKcV7ydxi0XJyTR1d3BI2X7SSsoy",
"tokens": [],
"role": "admin",
"__v": 0,
"profile": {
"name": "F.name L.name",
"gender": "Female",
"location": "my place",
"avatar": {
"contentType": "image/png",
"data": "iVBORw0KGgoAAAANSUhEUgAAAaYAAAFmCAYAAAAmm....."
}
}
}
]
对于显示的电子邮件,将渲染配置文件详细信息叠加到angular4上,没有任何问题。
<div *ngFor="let item of getProfile">
<h3>{{item.profile.name}}</h3>
<h4>{{item.email}}</h4>
<img src="{{item.profile.avator}}" alt="">
</div>