Query to find documents where field have data type string

Problem Statement

Write mongodb query to find document where field named 'name' have data type String

Collection Name: dataTypes

db.dataTypes.insertOne({
    "name": "Codediggy", 
    "32-bit integer": NumberInt(1),
    "64-bit integer": NumberLong(1000), 
    "decimal128": NumberDecimal(1.4), 
    "double": Double(1.5), 
    "boolean": true, 
    "object": { "field": "test" }, 
    "regular expression": /^c/, 
    "javascript": function square(num) {return num * num;}, 
    "timestamp": Timestamp(), 
    "date": Date(), 
    "min Key": MinKey(), 
    "max Key": MaxKey(), 
    "array": [], 
    "Null": null
})   

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

Solution

db.dataTypes.find({"name":{$type:"string"}})