0

Here is my screenshot, I don't understand why sometimes value being stored as a a number and sometimes as NumberInt.

enter image description here

And When i am try this query for search

{
    "price.egglessPrice" : { '$gt' : 360, '$lt':370}
}

I always get the result including above screenshot. but this is not right ans. There is no price lies between 360 to 370.

Nishchit
  • 18,284
  • 12
  • 54
  • 81

1 Answers1

1

The reason behind different data type of number value depends on how you are storing your value. And you have to use $elemMatch here for matching the results:

db.collection.find({
    price: {
        $elemMatch: {egglessPrice: { $gt: 360, $lt: 370}}
    }
});
Shashank Agrawal
  • 25,161
  • 11
  • 89
  • 121