1

I want to query using _id in array of object.

const members = [
  { _id: 60fb6f2859fd441f38e21172 },
  { _id: 60fb70a059fd441f38e21175 },
  { _id: 60fb6d9459fd441f38e2116c }
]

I know if it's an simple array, we can use $in operator. Please help how to query using above array.

const files = await File.find({ _id: { $in: members._id } });
  • 3
    Can't you just map the array like this: `members.map(item => item._id)` and use the result in the query? If you want to filter by an array of `_ids`, you need something like this: `["60fb6f2859fd441f38e21172", "60fb70a059fd441f38e21175", "60fb6d9459fd441f38e2116c"]` – Rafael Freitas Jul 24 '21 at 03:01
  • Does this answer your question? [mongodb/mongoose findMany - find all documents with IDs listed in array](https://stackoverflow.com/questions/8303900/mongodb-mongoose-findmany-find-all-documents-with-ids-listed-in-array) – SuleymanSah Jul 24 '21 at 09:55

0 Answers0