Find documents where a field is of any numeric type (double, int, long)

Problem Statement

Write mongodb query to find document where field named 'age' have any numeric data type

Collection Name: students

[
    {
      _id: ObjectId('6626fb9e6548c947e716c9b7'),
      name: 'Joe Rogan',
      age: 35,
      country: 'USA'
    }
] 

For more explaination of $type operator see : What is $type operator and how to use it?

Solution

db.students.find({"age":{$type:"number"}})

OR

db.students.find({"age":{$type:["double","int","long","decimal"]}})
Explaination:

When array is passed to $type operator then it will return document in which given field match any one of data type from the array.