A query returns no documents because the types differ
Locate the failed assumption, reproduce it, then repair the cause.
What actually caused it
MongoDB matches the value you stored, including its type. A field saved as the number 12 does not match a query that asks for the string "12". A field saved as a string id does not match a query that passes a number, and the reverse is the same miss. find returns an empty . findOne returns . The collection can still contain the document. The connection worked. The filter compared two values that look alike on the screen and are not equal in the database. Guessing that the collection is empty sends you to the wrong fix.
Minimal reproduction
Number stored, string queried
await books.insertOne({ title: 'Notes', pages: 12 });
const rows = await books.find({ pages: '12' }).toArray();
console.log(rows.length);
The length is 0. The document is still in the collection.
The fix
Print one stored document and read the type of the field you are filtering on. Pass that same type in the query. If you inserted a number, query with a number. If you inserted a string, query with a string. Do not convert the value only in the query while leaving the stored documents unchanged, unless you also update the stored values. Run the find again. An empty list after the types agree means the field name or the value is still different.
Query with the stored type
await books.insertOne({ title: 'Notes', pages: 12 });
const rows = await books.find({ pages: 12 }).toArray();
console.log(rows.length);
The number 12 matches the number that was inserted.