- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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" }
Advertisements