MongoDB "select x from y where id in" another table I'm trying to understand how can I achieve this in MongoDB:
select *
from Table1
where id in
(selct id from table2)

I'm trying to aggregate but I just can't understand how JSON works:
db.Collection1.find
    (
            {&quot;Field_from_Collection1&quot;:
                {$nin:db.Collection2.distinct(&quot;The_Field_I_want_to_compare&quot;)
                    
                }
                
            }
    ).limit(1)
    

I need to find all information from collection1, but only if the ID is in collection2.
The reason I'm doing this is that I need to find the documents in Collection1, that has specifics IDS, and it's 600k IDS to look for.
as a SQL Server DBA, I'm really struggling to do this.
You should use $lookup for subquery.
Check out the document.
There is an example from the document.
db.collection1.aggregate([
{
   $lookup:
     {
       from: &lt;collection to join&gt;,
       localField: &lt;field from the input documents&gt;,
       foreignField: &lt;field from the documents of the &quot;from&quot; collection&gt;,
       as: &lt;output array field&gt;
     }
}