
- MongoDB Tutorial
- MongoDB - Home
- MongoDB - Overview
- MongoDB - Advantages
- MongoDB - Environment
- MongoDB - Data Modeling
- MongoDB - Create Database
- MongoDB - Drop Database
- MongoDB - Create Collection
- MongoDB - Drop Collection
- MongoDB - Data Types
- MongoDB - Insert Document
- MongoDB - Query Document
- MongoDB - Update Document
- MongoDB - Delete Document
- MongoDB - Projection
- MongoDB - Limiting Records
- MongoDB - Sorting Records
- MongoDB - Indexing
- MongoDB - Aggregation
- MongoDB - Replication
- MongoDB - Sharding
- MongoDB - Create Backup
- MongoDB - Deployment
- MongoDB - Java
- MongoDB - PHP
- Advanced MongoDB
- MongoDB - Relationships
- MongoDB - Database References
- MongoDB - Covered Queries
- MongoDB - Analyzing Queries
- MongoDB - Atomic Operations
- MongoDB - Advanced Indexing
- MongoDB - Indexing Limitations
- MongoDB - ObjectId
- MongoDB - Map Reduce
- MongoDB - Text Search
- MongoDB - Regular Expression
- Working with Rockmongo
- MongoDB - GridFS
- MongoDB - Capped Collections
- Auto-Increment Sequence
- MongoDB Useful Resources
- MongoDB - Questions and Answers
- MongoDB - Quick Guide
- MongoDB - Useful Resources
- MongoDB - Discussion
Can we work MongoDB findOne() with long type _id?
Yes, we can do that using the NumberLong() datatype in MongoDB. Let us create a collection with documents −
> db.demo618.insertOne({_id:NumberLong("6336366454"),Name:"Chris"}); { "acknowledged" : true, "insertedId" : NumberLong("6336366454") } > db.demo618.insertOne({_id:NumberLong("6336366455"),Name:"David"}); { "acknowledged" : true, "insertedId" : NumberLong("6336366455") } > db.demo618.insertOne({_id:NumberLong("6336366456"),Name:"Bob"}); { "acknowledged" : true, "insertedId" : NumberLong("6336366456") }
Display all documents from a collection with the help of find() method −
> db.demo618.find();
This will produce the following output −
{ "_id" : NumberLong("6336366454"), "Name" : "Chris" } { "_id" : NumberLong("6336366455"), "Name" : "David" } { "_id" : NumberLong("6336366456"), "Name" : "Bob" }
Following is the query to implement MongoDB findOne() with long type _id −
> db.demo618.findOne({_id: NumberLong("6336366454")});
This will produce the following output −
{ "_id" : NumberLong("6336366454"), "Name" : "Chris" }
- Related Articles
- Usage of findOne() with MongoDB?
- Using regex in MongoDB findOne()
- Difference between find() and findOne() methods in MongoDB?
- How to work with id locator in WebdriverIO?
- Work with $push in MongoDB
- Can I retrieve multiple documents from MongoDB by id?
- Sort id and reverse the items with MongoDB
- MongoDB 'count()' is very slow. How do we work around with it?
- Can we update a row with the highest ID in a single MySQL query?
- Use ObjectId under findOne() to fetch a specific record in MongoDB?
- How to get element with max id in MongoDB?
- Update a MongoDB document with Student Id and Name
- How can we say that Energy= Stored work?
- Hide id field in MongoDB
- How to work with variables in MongoDB query

Advertisements