Join multiple collections on multiple keys using map reduce in Mongo DB.

100 views
Skip to first unread message

Anand Dayalan

unread,
Sep 26, 2012, 7:55:03 PM9/26/12
to mongod...@googlegroups.com

I know a way to join multiple collections using a same key, and I thinks its not possible to join multiple collections on multiple keys but wondering anyone know a way to do it.

Lets say I have a collection AAA with fields A, B, and C, and I have a collection called BBB with fields B, D and E, and I have another collection called CCC with fields C, F, G.

In collection AAA field B is DB Ref for field B in collection BBB, and field C in collection AAA is a DB ref for field C in collection CCC. Now I want join these three collections like AAA join BBB on AAA.B =BBB.B , BBB join CCC on BBB.C = CCC.C.

I know that I can embed one collection in another but I have a situation where I can't embed everything but need to do a adhoc report across multiple collection. So how do I do it?

David Hows

unread,
Sep 27, 2012, 1:47:46 AM9/27/12
to mongod...@googlegroups.com
Hi Anand,

MongoDB doesnt support joins natively, you will need to perform the joins within your application.

Cheers,

David

William Zola

unread,
Sep 27, 2012, 11:09:33 PM9/27/12
to mongod...@googlegroups.com
Anand -- are you trying to do this with standard queries, or with mapReduce?

 -William 
Reply all
Reply to author
Forward
0 new messages