> db.doc.find().pretty();
{
"_id" : ObjectId("55669401a5f628a23fed5adc"),
"cur" : {
"pathname" : "/blog",
"href" : "http://www.example.com/blog/"
},
"visits" : [
{
"url" : "http://www.example.com/blog/",
"gt_ms" : "1110"
}
]
}
{
"_id" : ObjectId("556697eba5f628a23fed5add"),
"cur" : {
"pathname" : "/twcontroller/insights/login.php",
"href" : "http://www.example.com/twcontroller/insights/login.php"
},
"visits" : [
{
"url" : "http://www.example.com/twcontroller/insights/login.php",
"gt_ms" : "990"
}
]
}
{
"_id" : ObjectId("556697eba5f628a23fed5ade"),
"cur" : {
"pathname" : "/",
"href" : "http://www.example.com/"
},
"visits" : [
{
"url" : "http://www.example.com/",
"gt_ms" : "719"
},
{
"url" : "http://www.example.com/",
"gt_ms" : "719"
}
]
}
{
"_id" : ObjectId("556697eba5f628a23fed5adf"),
"cur" : {
"pathname" : "/",
"href" : "http://www.example.com/"
},
"visits" : [
{
"url" : "http://www.example.com/",
"gt_ms" : "62"
},
{
"url" : "http://www.example.com/",
"gt_ms" : "62"
},
{
"url" : "http://www.example.com/",
"gt_ms" : "62"
},
{
"url" : "http://www.example.com/",
"gt_ms" : "62"
},
{
"url" : "http://www.example.com/",
"gt_ms" : "62"
},
{
"url" : "http://www.example.com/",
"gt_ms" : "62"
},
{
"url" : "http://www.example.com/",
"gt_ms" : "62"
}
]
}
我希望能够将
cur.pathname
的值与visits[0].url
(即数组visits中的第一个元素)进行匹配,并返回其计数。同时,我还想返回只有一个数组元素的visits数组的计数。
我该如何做到这一点?
cur.pathname
和visits[0].url
,它总是会返回False
。你是不是想说cur.href
和visits[0].url
? - thegreenogre$slice
运算符,或者查看这个答案来在聚合中完成它。 - thegreenogre