Skip to content
Advertisement

Conditional joins on collections using mongoose

I’m new to mongoDB, I am trying to achieve the following SQL query on it. but could not find anything useful so far. can anyone tell equivalent mongoose query

JavaScript

what I got so far is following

JavaScript

UPDATE

I have following name and export scheme

JavaScript

Advertisement

Answer

You can use filter out objects included in resulting array using match but in the case if it couldn’t find any, it would still return a null value. So in comparison this works similar to sql left join.

JavaScript

Also see https://mongoosejs.com/docs/populate.html#query-conditions

If you need strictly a inner join then you can use mongodb aggregate pipeline.

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement