我无法理解猫鼬的人口逻辑。
我有一个包含一系列文章的 UserSchema。
articles: {
type: [{
article: {
type: Schema.Types.ObjectId,
ref: "Article"
},
read: Boolean,
starred: Boolean
}]
},
文章存储在单独的集合中。现在我想查找用户的所有已加星标的文章,填充这些文章,按发布日期对它们进行排序并对结果进行分页。
User.findOne({_id: user.id, "articles.starred": true}).populate({path: "articles.article", options: {sort: {"published": -1}, skip: 20, limit: 20}}).exec(function(err, _user) {
callback(_user);
});
问题是,人口已经完成,但选项被完全忽略了。
以下是用户和文章的外观:
用户:
{
"__v" : 0,
"_id" : ObjectId("5284ef45fe46a55194000003"),
"articles" : [
{
"article" : ObjectId("5284ef52fe46a55194000005"),
"read" : true,
"starred" : true,
"_id" : ObjectId("5284ef53fe46a55194000ae1")
}
],
"categories" : [
{
"_id" : ObjectId("5284ef52fe46a55194000004"),
"feeds" : [
{
"url" : "http://feeds.dzone.com/zones/dotnet",
"name" : ".NET Zone - Community for .NET developers everywhere"
}
],
"name" : ".NET"
}
],
"email" : "xxxx",
"google" : {},
"name" : "xxxx",
"provider" : "xxxx"
}
文章:
{
"author" : "Michael Hession",
"title" : "You'll Never Want to Put Away This Elegant Pour-Over Coffee Dripper",
"published" : ISODate("2013-06-13T16:38:00.000Z"),
"link" : "http://gizmodo.com/youll-never-want-to-put-away-this-elegant-pour-over-co-513136433",
"feed" : {
"title" : "Gizmodo",
"link" : {
"html" : "http://gizmodo.com",
"xml" : "feed/http://feeds.gawker.com/gizmodo/excerpts.xml"
}
},
"summary" : "html content",
"_id" : ObjectId("5284ef52fe46a55194000005"),
"__v" : 0
}