Insert in mongo shell with specific data type

Hello, How can we make sure a filed has specific type when we inserting? For example, when we insert document in compass we can specify int32 for year filed but how do we do it in mongo shell?

Mongo Shell automatically inferred the data type of the value. But you can still use built-in helper methods like NumberLong, NumberInt, NumberDecimal for some specific type. I hope the answer helps
According to mongodb online manual Data Types in mongo shell

1 Like

Thank you Sidoine_Komi., yes it helped. mongo shell automatically inferred as data type of double for year.

using following we can make sure data type of int32 for year.
year: NumberInt(1998)

Great… Happy learning dear

1 Like