【发布时间】:2015-05-28 05:51:24
【问题描述】:
> 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 匹配(即数组中的第一项访问)并返回其计数。还想返回只有一个数组元素的访问次数数组。
我该怎么做?
【问题讨论】:
-
如果您比较
cur.pathname和visits[0].url,查看您的示例文档,它总是会产生False。你是说cur.href和visits[0].url吗? -
我需要访问数组中的第一个 url 值,表示第一个索引处的 url 值。像 JS 中的访问[0].url