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?
db.students.find({"age":{$type:"number"}})
db.students.find({"age":{$type:["double","int","long","decimal"]}})
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.