我在数组中有一个名为blogs的数组存在这些对象:
var blogs = new mongoose.Schema({
title: String,
image: String,
body: String,
author: {
id: {
type: mongoose.Schema.Types.ObjectId,
ref: "User"
},
username: String
},comments: [
{
type: mongoose.Schema.Types.ObjectId,
ref: "Comment"
}
],
created: {type: Date, default: Date.now}
});
我想创建一个仅显示具有相同用户名示例admin的博客的forEach。 我的forEach代码
blogs.forEach(function(blog){
// prints blogs
}