如果我的数据库如下,我如何计算总数的电影数量? 我想要一个类似的输出
N_Movies:3
我在网上搜索但找不到办法。
我真的很感谢你的帮助!
"Movies":
[
{ "Date": "15/01/2016",
"Time": "00:57:00",
"Title": "Resident Evil",
"License": { "Date": "15/01/2016", "Time": "00:00:00"},
"Viewing PCT": 99
},
{ "Date": "22/01/2016",
"Time": "22:01:00",
"Title": "Whatever It Takes",
"License": { "Date": "22/01/2016", "Time": "00:00:00"},
"Viewing PCT": 1
}
答案 0 :(得分:0)
我在想你正试图找到数组的大小。您可以使用$size聚合来获取数组的大小
db.aggregate([{'$project':{'N_Movies':{'$size':'$Movies'}}}])