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

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?

Answers


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

You can use

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

Need Your Help

How to set a custom useragent string in Mojo::UserAgent

perl user-agent mojo mojolicious

We have a bunch of code built around Mojo::UserAgent and migrating to MojoX::UserAgent is not quite an option. I wonder if there is a way to get/set user agent string in Mojo::UserAgent?

How to serialize a JavaScript associative array?

javascript jquery arrays forms

I need to serialize an associative JavaScript array.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.