I use mongodb for my project.
when I put in this code - db.find( {"N": {$eq:1} } ) , the result is a empty array.
but when I put this code - db.find({$where : function(){return(this.N==1)}}), the result is the array that I want.
I think two codes are same. why is the result of first code an empty array?
The value is not a number as you claim, the syntax == is different than the strict eq operator === ( which is the equivalent~ of Mongo's $eq ) as can be seen in this example
1 == `1`
> true
While the strict operator
1 === '1'
> false
So you just need to change the code to match the string '1', like so:
db.find( {"N": {$eq:'1'} }
Or if you want to support both cases:
db.find( {"N": {$in: [1, '1']} }
I recommend you fix your schema and db to make sure it's aligned to what you believe the structure should be.