Ramesh
unread,May 3, 2012, 3:50:42 PM5/3/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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.