Search code examples
mongodbmongodb-querymongodb-java

How to find datatype of all the fields in Mongo


I have a doc

{_id:NumberLong(1),gender:"M",vip:false}.

How to extract the type of individual field in Mongo with a query.. How to use typeof operator:

https://docs.mongodb.org/manual/core/shell-types/


Solution

  • > db.test.findOne()
    { "_id" : NumberLong(1), "gender" : "M", "vip" : false }
    > db.test.findOne().gender
    M
    > typeof db.test.findOne().gender
    string