Filter data from multiple strings array from object and exclude from array of strings

  const door4 = ObjectId("someId");
      const door3 = ObjectId("someId");
      const Automatic = ObjectId("someId");

      const filterPosts = await VFSPostViewSchema.aggregate([
        {
          $match: {
            $and: [
              { "filterItem.id": { $in: [door4, Automatic] } },
              { "filterItem.id": { $nin: [door3] } },
            ],
          },
        },
      ]);

its my code i have condition in which i have two arrays includes and excludes
includes array = [“id1”,“id2”,“id3”] this will be the excat match i need that same data which match these all ids and dont return that if any one of that match i want to get those document which have all of this

exclude. array = [“id4”,“id5”,“id6”] i need to exclude all that document which has that ids

Hi @Mehmood_Zubair and welcome to the community!!

To understand the problem in a better way, it would be very helpful if you could help with some details on the topic:

  1. A sample scheme or document for the same which would help me reproduce in my local environment.
  2. The query that you have tried and the response received
  3. Expected response.
  4. MongoDB and driver version
  5. Can you also confirm if the screenshot you posted is the expected response for the query mentioned.

Regards
Aasawari

1 Like