'Mongodb run $in on an array
i am trying to do a simple query, which is based on array of objects. fieldA
is an array of objects and my query looks something like this
const books = [
{name: 'LOTR', author: 'J.R Tolkien'},
{name: 'HP', author: 'JK. Rowling'},
{name: 'Witcher', author: 'A. Sapkowski'}
];
const exists = await Book.exists({ fieldA: { $in: books } });
I am trying to see if the books in books
array exist in database by implementing a search on fieldA
which is an array of objects. The problem is that $in
seems to take only one entity and it always returns false this way. Is there any way i can use $in
but on array of objects?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|