Hello.
Why so limitation in mongo, that I can not run db.eval (JavaScript
function) on sharded collection?
May be mongodb has undocumented features how to do it?
---------------------------------------------------------------------
My problem is following:
I has "views_raw" collection, which is sharded and every 5 minuts to
this collection writes 100K rows.
One row looks like:
{
"_id": ObjectId("4fcf7349d144ad591c016534"),
"sid": 111,
"uh": "
www.site.kz",
"cid": "4facd5427701a",
"ses": "4fcf7278f1f19",
"ip": NumberInt(1597732605),
"t": ISODate("2012-06-06T15: 08: 40.0Z"),
...
}
I need run task, which writes to another sharded collection
"last_ses_active" information about last access of session:
{
"_id": {sid: 111, ses:"4fcf7278f1f19"},
"t": ISODate("2012-06-06T15: 08: 40.0Z"),
}
So from this table I can obtain (via MR) total amount of unique
sessions (ses) for each site (sid) for any arbitrary period of time.
For example: site 111 has 123003 unique sessions for last 24 hours.
So I want run JavaScript code via $MongoDB->command(array('$eval' =>
$code, 'nolock'=>true));
$code = '
var out = db.last_ses_active;
db.views_raw.find(
{"t": {"$gte": ISODate("2012-05-29T18: 00: 00.0Z"), "$lte":
ISODate("2012-05-29T18: 59: 59.0Z")}}
)
.forEach(
function(x) {
out.update(
{_id:{sid: x.sid, ses: x.ses}},
{_id:{sid: x.sid, ses: x.ses}, t: x.t},
upsert = true
);
}
);
';
This command I can parallize, write checks, catch errors AND IT WILL
BE VERY SPEEDLY.
Of course, I can use MapReduce with {merge : "last_ses_active" }, but
It very expensive and slowly:
- MapReduce makes conversations between BSON to JS and vice versa many
time (jsMode flag can't use, because too much data will be in future,
more than 500k unique keys)
- MapReduce creates temprory tables (but in my task not need to do it,
I can write data directly)
Of course, I can do it via client. But I dont want move huge amount
data between client and server.
Please help to solve my problem, how to count unique sessions for each
site for some period of time (from now to past).
Thanks.
P.S. And why did not do work JavaScript on sharded collections?
Indeed!