- 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
How I can use a database-name with special characters like " customer_tracker-990" in MongoDB console
Yes, use getSiblingDB(). Let us add some documents to the database −
> use customer_tracker-990; switched to db customer_tracker-990 > db.demo1.insertOne({"Name":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea4697ca7e81adc6a0b3954") } > db.demo1.insertOne({"Name":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea46980a7e81adc6a0b3955") } > db.demo1.insertOne({"Name":"Bob"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea46984a7e81adc6a0b3956") }
Display all documents from a collection with the help of find() method −
> db.getSiblingDB("customer_tracker-990").demo1.find();
This will produce the following output −
{ "_id" : ObjectId("5ea4697ca7e81adc6a0b3954"), "Name" : "Chris" } { "_id" : ObjectId("5ea46980a7e81adc6a0b3955"), "Name" : "David" } { "_id" : ObjectId("5ea46984a7e81adc6a0b3956"), "Name" : "Bob" }
Advertisements