passing an array to the .group function (nodejs and mongodb)

26 views
Skip to first unread message

Ramesh

unread,
May 3, 2012, 3:50:42 PM5/3/12
to mongodb-user
I am a newbie and learning, mongodb version 2.0.1, and nodejs
I learnt a lot by looking at the groups, but not many posts
about .group() aggregate function.

I have a main collection releases with a mill rows:
{
"_id" : ObjectId("4f8795337eff37dfe18510dd"),
"chmid" : 555,
"other" : 0
}

Another chems
{
"_id" : ObjectId("4f888870a75a4247f0e79205"),
"chmid" : 555,
"chmname" : "METHANOL"
}

I group on the releases, and try to retrieve the chmname from a cached
array.
in node.js I have this code:

releases.group(
{ chmid: true },
{ y: 1},
{ total_count: 0, row_ctr: 0, cmps: [], lkp:
this.cachedChemNames },
function (doc, out) {
out.total_count += doc.Total;
var chmidx = doc.chmid - 1; <-- index
matches chmid
out.chmname = lkp[chmidx]; <---
db.findOne() takes a longer time, hence using a cached array
out.row_ctr++;
},
function (out) { },
function(err,doc){});

Any help greatly appreciated! Thanks.

Mike O'Brien

unread,
May 3, 2012, 5:55:12 PM5/3/12
to mongodb-user
Hi Ramesh,

What's the issue you're having with this code? Is it returning an
error message?

-Mike

Ramesh

unread,
May 4, 2012, 12:59:31 PM5/4/12
to mongodb-user
No error message is returned. I don't see any results.
I see the results if the offending line is removed. I see results if
findOne() is used.
Is there a way to debug that procedure ? console.log or sys.put dont
show any output either.

Mike O'Brien

unread,
May 29, 2012, 11:30:41 AM5/29/12
to mongodb-user
Ramesh,
Are there any error messages being printed to the server logs? I'm
getting "JS Error: ReferenceError: lkp is not defined"
I think you need to reference it as "out.lkp"
You can use print("message") for debugging, these messages will get
printed to the server logs as well.
Reply all
Reply to author
Forward
0 new messages