I am newbie to mongodb. I need to do a query by joinin two collections.
comments
{ uid:12345, pid:444, comment="blah" }
{ uid:12345, pid:888, comment="asdf" }
{ uid:99999, pid:444, comment="qwer" }
users
{ uid:12345, name:"john" }
{ uid:99999, name:"mia" }
query: Select c.pid, c.comment from comments c, users u uwhere c.uid = u.uid;
I need to perform it using java api for mongodb. I know that mongodb doesnot support joins. I have an idea to implement, but I dont know whether its the best one.
idea:
performing two queries by splitting it. ( retrieving the uuid from users collections and checking against uuid of comments collection)
Any other idea to implement it? Could anyone send me the mongodb java code to perform this query by spliting into two queries and getting the result.
or using DBRef