
- 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
MongoDB query to retrieve records from a collection named with letters and numbers
At first, let us create a collection with letters and numbers, for example −
7664734-541d-r5i5f-845575e-ghfhjrjr3747_demo368
Access the above collection using db.getCollection(). Let us now create a collection with the name mentioned above −
> db.createCollection('7664734-541d-r5i5f-845575e-ghfhjrjr3747_demo368'); { "ok" : 1 } >db.getCollection('7664734-541d-r5i5f-845575e-ghfhjrjr3747_demo368').insertOne({"FirstName":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e57e2152ae06a1609a00aea") } >db.getCollection('7664734-541d-r5i5f-845575e-ghfhjrjr3747_demo368').insertOne({"FirstName":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5e57e21a2ae06a1609a00aeb") } >db.getCollection('7664734-541d-r5i5f-845575e-ghfhjrjr3747_demo368').insertOne({"FirstName":"Bob"}); { "acknowledged" : true, "insertedId" : ObjectId("5e57e21e2ae06a1609a00aec") }
Display all documents from a collection with the help of find() method −
> db.getCollection('7664734-541d-r5i5f-845575e-ghfhjrjr3747_demo368').find();
This will produce the following output −
{ "_id" : ObjectId("5e57e2152ae06a1609a00aea"), "FirstName" : "Chris" } { "_id" : ObjectId("5e57e21a2ae06a1609a00aeb"), "FirstName" : "David" } { "_id" : ObjectId("5e57e21e2ae06a1609a00aec"), "FirstName" : "Bob" }
- Related Articles
- MongoDB: How to query a collection named “version”?
- Retrieve data from a MongoDB collection?
- Get the maximum mark records from a collection with documents in MongoDB query
- How to retrieve documents from a collection in MongoDB?
- How to retrieve all nested fields from MongoDB collection?
- Query MongoDB collection starting with _?
- Get the maximum mark records from a collection with documents in MongoDB
- MongoDB query to remove entire data from a collection
- MongoDB query to pull array element from a collection?
- MySQL query to count records that begin with specific letters
- Retrieve records whenever a column value starts with 2 vowel letters in MySQL
- How to retrieve all the documents from a MongoDB collection using Java?
- MongoDB query to update a specific document from a collection
- MongoDB query to remove entire array from collection?
- MySQL query to retrieve records from the part of a comma-separated list?

Advertisements