1
我想保持可疑流量的集合,它类似于下面的模式:MongoDB的日志记录可疑流量
"_id": ObjectId(###),
"count": NumberInt(6),
"ip": NumberInt(2147483647),
"requests": {
[ "uri": "/path/to/something/",
"last": NumberInt(1419023477)
"count": NumberInt(2) ],
[ "uri": "/path/to/something/else/",
"last": NumberInt(1419023478)
"count": NumberInt(4) ]
}
有人可以帮我一个UPSERT会:
- 添加请求URI到嵌入文档数组
- 递增该URI的请求数
- 设置该URI的最后一个请求日期
- 最后增加总体要求数为IP
有人问我后我已经这么远:
$db->coll->update(array('ip' => $ip),
array('$addToSet' => array('req' => array('$set' => array('last' => $timestamp),
'$inc' => array('count' => 1)))),
array('upsert' => true)
);
正如你所看到的,它没有搜索嵌入文档与相应的uri($ uri)
您编写的代码,我们帮助解决它。而不是相反。 –
请编辑该问题以添加您尝试过的实现。 – BatScream
您的文档结构无效。请求是否意味着是一组对象? – wdberkeley