I'd like to keep a collection of suspicious traffic that resembles the following schema:
"_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) ]
}
Can somebody help me with a single upsert that will:
- add the request URI to the embedded document array
- increment the number of requests for that URI
- set the last request date for that URI
- and finally increment overall request count for that IP
Somebody asked me to post what I've got so far:
$db->coll->update(array('ip' => $ip),
array('$addToSet' => array('req' => array('$set' => array('last' => $timestamp),
'$inc' => array('count' => 1)))),
array('upsert' => true)
);
As you can see, it's not yet searching for the embedded doc with the matching uri ($uri)