I have Book objects in my mongoDb that look like this (very simplified):
{
"_id": ObjectId("620e341dbf575892d9396dc2"),
"title": "my title",
"author": {
"_id": ObjectId("620e341dbf575892d9396dd4"),
"surname": "My surname"
}
}
I'm trying to query and get all books by an author, and so far I've tried:
const booksByAuthor = await Book.find({ author: { _id: "620e341dbf575892d9396dd4" } });
and
const booksByAuthor = await Book.find({ 'author._id': "620e341dbf575892d9396dd4" } );
But in no case I'm getting the existing books from the given author, and I'm only getting empty arrays.
What am I doing wrong?