

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 }
- Related Questions & Answers
- How to insert Date in MongoDB?
- How to insert a Python object in Mongodb?
- How to insert a boolean field in MongoDB?
- How to insert a document with date in MongoDB?
- Generate Random Long type numbers in Java
- Insert in MongoDB without duplicates
- Perform Bulk insert in MongoDB?
- How to validate documents before insert or update in MongoDB?
- How to convert Long array list to long array in Java?
- MongoDB bulk insert for documents
- Insert to specific index for MongoDB array?
- Convert long primitive to Long object in Java
- Insert data into inner array in MongoDB?
- How to insert new documents into a MongoDB collection in your database?
- How to insert a document into a MongoDB collection using Java?
Advertisements