top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to remove a collection from a database in mongoDB system ?

0 votes
570 views
How to remove a collection from a database in mongoDB system ?
posted Jun 21, 2015 by Ganesh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Trigger the following command to remove a collection from the database.

db.collection_name.drop()

You can verify by issuing following command.

show collections

answer Jun 21, 2015 by Harshita
Similar Questions
+3 votes

Here I would like to explain my query a bit more.

I inserted multiple documents within a collection. Few documents have same set of keys and few of them have some extra key:value pairs . For example:
document 1 : key1 : "key1"
document 2: key1 : "key1", key2: "key2"
document 3: key1 : "key1", key2: "key2", key3 : "key3"
document 4: key1 : "key1", key3 : "key3"

Now I want to delete the documents which have key1 and key2.
What will be the command to do so ?

+2 votes

From Mongodb client, we can use db.Collection.stats() to get status of collections, such as:

+ Number of records (count) 
+ Size on disk (storageSize) 
+ Indexes (indexSizes) 
+ Average object size (avgObjSize) 

Now I want to monitor these data from web backend with Mongodb java driver, please let me know how to get them?
I've referred: http://mongodb.github.io/mongo-java-driver/3.0/driver-async/getting-started/quick-tour-admin/ but it's not enough information for me. Any pointer?

...