Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove collection named 'group'?

Tags:

mongodb

I accidentally created a collection named 'group'. How do I remove it.

When I give the following in the mongo console

 db.group.drop()

I get the following error

Fri Jun  7 16:36:39.630 JavaScript execution failed: TypeError: Object function ( parmsObj ){
     var ret = this.runCommand( { "group" : this._groupFixParms( parmsObj ) } );
     if ( ! ret.ok ){
         throw "group command failed: " + tojson( ret );
     }
     return ret.retval;
} has no method 'drop'
like image 239
Jibin Avatar asked Jun 07 '13 11:06

Jibin


People also ask

How do I remove all records from a collection?

To delete all documents in a collection, pass an empty document ( {} ). Optional. To limit the deletion to just one document, set to true . Omit to use the default value of false and delete all documents matching the deletion criteria.

Which function will remove collection in MongoDB?

The remove() Method MongoDB's remove() method is used to remove a document from the collection.


1 Answers

The problem is that group is a method on a database object. So, db.group cannot be used to get the actual collection named group. Instead, use .getCollection():

db.getCollection('group').drop()
like image 66
alecxe Avatar answered Sep 21 '22 20:09

alecxe