【发布时间】:2016-08-04 10:54:42
【问题描述】:
我的文档是这样的。
{
"_id" : ObjectId("572c4bffd073dd581edae045"),
"name" : "What's New in PHP 7",
"description" : "PHP 7 is the first new major version number of PHP since 2004. This course shows what's new, and what's changed.",
"difficulty_level" : "Beginner",
"type" : "Normal",
"tagged_skills" : [
{
"_id" : "5714e894e09a0f7d804b2254",
"name" : "PHP"
}
],
"created_at" : 1462520831.649,
"updated_at" : 1468233074.243 }
是否可以在单个查询中获取最近的 5 个文档和总数。 我正在使用两个查询来满足这个要求,如下所示。
db.course.find().sort({created_at:-1}).limit(5)
db.course.count()
【问题讨论】:
标签: javascript mongodb performance mongodb-query