Increase efficiency by comparing a field with a Mongodb Jdbc multiple collection


Hi , I have one SQL query i'm trying to implement it in MongoDB using MongoJava driver Jdbc [2.10]. My sql query is,

SELECT DISTINCT FROM table1,table2 WHERE table1.x = table2.x and
table1.y IN ( somevalue ) AND  table2.y IN (somevalue)

In MongoDB i have Table1 collection and Table2 collection. Using Jdbc i created two object to access two collection. Consider i have 1 lack record in each collection. If i try to compare each single document value with another collection, it takes 1 lack * 1 lack comparison. ?? after that i want to match it with 'y' value ??

Can any one suggest me how can i efficiently convert this query to MongoDB jdbc query ??


mongdb doesn't support joins like that so you'd need to do multiple queries. something like this maybe:

db.collection1.distinct( 'id', { y: { $in: [...] } } )

then take those IDs and do another $in query against collection2.

Though, I have to ask why you'd have a table without unique IDs.