Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to delete a collection in mongodb which has space in between its name i.e.'Coimbatore Express'?

Tags:

mongodb

this code will show the error am facing the collection which am trying to delete is 'Coimbatore Express' and problem is I have a space between Coimbatore & Express.

enter image description here

like image 387
Akshay Raj Avatar asked Aug 22 '17 15:08

Akshay Raj


People also ask

Which query is used to remove a collection in MongoDB?

The db. collection. remove() method is used to remove documents from a collection.

How do I delete a collection in MongoDB Atlas?

The drop command removes the specified collection or view from the federated database instance storage configuration.

How do I delete multiple collections in MongoDB?

In MongoDB, you are allowed to delete the existing documents from the collection using db. collection. deleteMany() method. This method deletes multiple documents from the collection according to the filter.


1 Answers

Either try using a dot(.) operator to replace the space.

db.Coimbatore.Express.drop() 

Or alternatively as mentioned in the documentation use getCollection as:

db.getCollection("Coimbatore Express").drop()
like image 125
Naman Avatar answered Nov 15 '22 09:11

Naman