Mongodb group joining two collection

45 views
Skip to first unread message

marcolinux

unread,
Apr 23, 2012, 8:29:19 AM4/23/12
to mongod...@googlegroups.com

 I was wondering if it possible to using group (specifically, in the keyf function) to join 2 collections.

MYCOLL.collection.group(:keyf => "function(doc) { var var2Item=db.mycoll2.find({\"_id\":doc.my_sub_id}); var2=var2Item.join_var; return {'myreturn': doc.var1 + var2 }; }",     
:initial => { :r => 0 }, 
:reduce => "function(doc,prev) { prev.r += +1; }", 
:cond => {( ...my_conditions...)})

I have also tried

var2=doc.my_sub_id.join_var    

and neither seems to work. I am using the Ruby Driver, but it is not really important, as the query is (practically) raw.

Sam Millman

unread,
Apr 23, 2012, 8:54:00 AM4/23/12
to mongod...@googlegroups.com
I don't think the db object is available witin the group, does it just output an error or nothing at all?

--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To view this discussion on the web visit https://groups.google.com/d/msg/mongodb-user/-/YjCuh0Qr1OwJ.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.

marcolinux

unread,
Apr 23, 2012, 11:01:11 AM4/23/12
to mongod...@googlegroups.com
There is no error, but in all case it is outputting "undefined" (so it is not recognizing the query).

On Monday, April 23, 2012 9:54:00 PM UTC+9, Sammaye wrote:
I don't think the db object is available witin the group, does it just output an error or nothing at all?

Sam Millman

unread,
Apr 23, 2012, 11:12:32 AM4/23/12
to mongod...@googlegroups.com
Yea you can't do that, it was a long shot to see but hey.

In order to join you'll have to find some other way join them.

--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To view this discussion on the web visit https://groups.google.com/d/msg/mongodb-user/-/-3EW5Vr_MB8J.
Reply all
Reply to author
Forward
0 new messages