- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Does Mongo shell treats numbers as float by default.? How can we work it around explicitly?
Yes, Mongo shell treats numbers as float by default. To work it as int or any other type, you need to mention explicitly. You can use NumberInt() for this. The syntax is as follows −
var anyVariableName= [NumberInt("yourValue1"), NumberInt("yourValue2"),.....N];
Let us implement the above syntax in order to treat numbers as integer only (not float) −
> var integerArrayDemo = [NumberInt("50"), NumberInt("60"), NumberInt("70"),NumberInt("90"),NumberInt("40")];
Following is the query to display the array value −
> printjson(integerArrayDemo);
This will produce the following output −
[ NumberInt(50), NumberInt(60), NumberInt(70), NumberInt(90), NumberInt(40) ]
To display the array value, you can use print() −
> print(integerArrayDemo);
This will produce the following output −
NumberInt(50),NumberInt(60),NumberInt(70),NumberInt(90),NumberInt(40)
Advertisements