How do you do nested select in MongoDB analogous to
SELECT id FROM table1 WHERE id IN (SELECT id FROM table2)
MongoDB does not yet possess the ability to do subqueries which would allow this functionality.
I am sure it is something within the JIRA however, I could not immediately find it.
The only way currently is to actually pick the table, iterate the cursor pulling out the information and using that as part of a $in query as shown by @Bruno, like so:
ids=[];
for(i in db.c2.find({},{_id:1}){ // I have assumed id=_id
ids[ids.length]=i; // The default return of the index pos is actually _id
}
return db.c1.find({$in:ids});
As a mere example I wrote off of the top of my head.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With