How to insert LONG numbers in MongoDB?


To insert LONG numbers, use NumberLong(). It is used to handle 64-bit integers. Let us create a collection with documents −

> db.demo273.insert({
...   Name:"Robert",
...   id: NumberLong("100000000000001"),
...   isActive:true
...})
WriteResult({ "nInserted" : 1 })
> db.demo273.insert({
...   Name:"David",
...   id: NumberLong("98888888888888888"),
...   isActive:false
...})
WriteResult({ "nInserted" : 1 })
> db.demo273.insert({
...   Name:"Mike",
...   id: NumberLong("999999999999"),
...   isActive:true
...})
WriteResult({ "nInserted" : 1 })

Display all documents from a collection with the help of find() method −

> db.demo273.find();

Output

This will produce the following output −

{ "_id" : ObjectId("5e4824df1627c0c63e7dbac3"), "Name" : "Robert", "id" : NumberLong("100000000000001"), "isActive" : true }
{ "_id" : ObjectId("5e4824e01627c0c63e7dbac4"), "Name" : "David", "id" : NumberLong("98888888888888888"), "isActive" : false }
{ "_id" : ObjectId("5e4824e11627c0c63e7dbac5"), "Name" : "Mike", "id" : NumberLong("999999999999"), "isActive" : true }

Updated on: 31-Mar-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements