Skip to content
Advertisement

Mongo shell query is not working on mongoose

I have written a shell query which works perfectly on mongo shell but is not returning any value when run using mongoose in nodejs + typescript;

Mongo shell

JavaScript

But when I run the same query using mongoose in one of my routes.

Mongoose :

JavaScript

I would really appreciate if someone could help me with this. Because it took me a while to make this query on shell.

Advertisement

Answer

You can’t compare ObjectId and String.

you have to convert it ObjectId

JavaScript

JavaScript
Advertisement