0
我的文档如下所示。查找并计入单个mongodb查询
{
"_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()
你能否向我解释一下$$ ROOT。 –
@jarryjafery ['$$ ROOT'](https://docs.mongodb.com/manual/reference/aggregation-variables/#variable.ROOT)是MongoDB中的一个系统变量,它允许您访问正在处理的文档。当我有一点时间时,我会给我的答案添加一个解释。 – styvane
是的请谢谢先生 –