3
votes

As per "MongoDB - The definitive guide",

  • JavaScript has only a float type whereas MongoDB has a 4-byte integer, an 8-byte integer and an 8-byte float
  • By default all the numbers will be treated as double

When I tried to insert a integer, I am getting the following:

> n = {"myInteger" : 3 };    
{ "myInteger" : 3 }    
> db.num.insert(n);
> n = db.num.find();    
{ "_id" : ObjectId("4eeee1e5b593471ba5461577"), "myInteger" : 3 }

Based on the above, I have the following questions:

  • How do I insert an 8-byte integer into MongoDB through JavaScript?
  • How do I check the type of the myInteger value displayed above, by JavaScript?
  • How do I check the type of the myInteger value stored in MongoDB?
1

1 Answers

5
votes

How do I insert an 8-byte integer into MongoDB through JavaScript?

You can use

n = {"myLong" :  new NumberLong("123212313")};