我想找到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