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" }
Updated on: 2020-05-13T10:25:43+05:30

430 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements