我想找到4条有图像的帖子。我使用此代码:如何在猫鼬中工作
Post.find({}, function (err, posts) {
if (err) {
req.flash('error', 'An unknown error has occurred.');
res.redirect('back');
} else {
res.render("home", {posts});
});
}
}).exists(image, true).limit(4).sort({ date: -1 });
一个岗位的样子:
{
"_id" : ObjectId("586e15b21f647007ec22a171"),
"title" : "Some title is here",
"category" : "node",
"body" : "Lorem ipsum dolor sit amet",
"image" : "1486300310990-14775211410_42b8d244da_o.jpg",
}
因此它不具有任何图像后,应跳过。 这样的:
{
"_id" : ObjectId("586e15b21f647007ec22a171"),
"title" : "Some title is here",
"category" : "node",
"body" : "some txt"
}
但它不工作的乐趣,你能帮我吗?
你有没有定义的图像作为模型的一部分吗?你能展示模型吗? – notionquest
是的,我有。最好找到4个图像长度大于0的帖子。 – Joseph