Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert in an 8-byte integer into MongoDB through JavaScript shell?

Tags:

mongodb

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?
like image 789
Ken Russell Avatar asked May 04 '26 07:05

Ken Russell


1 Answers

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

You can use

n = {"myLong" :  new NumberLong("123212313")};
like image 135
Thilo Avatar answered May 05 '26 20:05

Thilo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!