skip to Main Content

I have 2 arrays with different ids :

  1. bikesWithNoOrders [id , id1 , id2]
  2. filteredResult [id3 , id5]

How do I make a query that finds them all

I have this :

queryBuilder.find({ _id: { $in: bikesWithNoOrders } });

queryBuilder.find({ _id: { $in: filteredResult } });

But the second one overwrites the first one because they dont share the same ids
I want something like this :

queryBuilder.find({ _id: { $in: filteredResult } }).or({ _id: { $in: bikesWithNoOrders } });

2

Answers


  1. You can just marge these 2 arrays on server side, and query with merged array. You can do it with concat():

    queryBuilder.find({ _id: { $in: bikesWithNoOrders.concat(filteredResult) } });
    
    Login or Signup to reply.
  2. Hope this answer will work for you.!

    queryBuilder.find({ _id: { $in: [...bikesWithNoOrders,...filteredResult] } });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search