Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear/drop/empty a MongoDb collection with Casbah

I started using MongoDb in Scala via Casbah but cannot find on the Casbah documentation / google the way to drop the content of a collection. The MongoDd doc says the MongoDb shell command to do so is

db.things.remove({}); 

But how can we achieve the same via Casbah?

Thanks in advance,

Olivier

like image 391
jolivier Avatar asked Sep 05 '12 22:09

jolivier


People also ask

How do I empty a MongoDB 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 command will remove all documents in a collection with field age set to 10?

remove() The remove() method removes documents from the database. It can remove one or all documents from the collection that matches the given query expression.

How do I drop a collection in MongoDB Atlas?

The drop command removes the specified collection or view from the federated database instance storage configuration. Use the wildcard "*" to remove all collections generated by the wildcard collection function (that is, collectionName() ), including the wildcard collection rule itself.


1 Answers

Casbah's equivalent to the shells {} empty document operator is `MongoDBObject.empty

This should work -

db.things.remove(MongoDBObject.empty)
like image 66
Brendan W. McAdams Avatar answered Nov 16 '22 01:11

Brendan W. McAdams