I have a document that is storing the _id field as: Long(“12345”).
When querying that document using find({_id: 12345})
it’s returning incorrect results.
I’ve tested by wrapping the find logic in a Long and NumberLong function and that returns the correct row.
Examples below work:
find({_id: Long("12345")})
find({_id: NumberLong("12345")})
I’m mostly wondering that once a document is storing a field as Long(“12345”), Mongo must not be able to implicitly convert the find logic to get the correct row, unless you wrap it in the Long or NumberLong function?
I tested it in my environment using mongosh in MongoDB 6.0.5 after inserting {_id: Long("12345")} and it worked fine for me. Sharing the command snippet for your reference:
Could you please share how you executed those commands and which specific MongoDB version you are using? Also, let me know if you have any further questions or doubts.