sanbhat
sanbhat

Reputation: 17622

MongoDB Java API - whats the equivalent for db.collection.remove()?

As explained here, db.bios.remove() deletes all the documents from the bios collection of currently connected DB. What is the equivalent method for this functionality in MongoDB Java API?

I did not find any methods like DB.removeCollection(..) or DBCollection.removeAll(). Please help me.

Upvotes: 0

Views: 130

Answers (1)

Philipp
Philipp

Reputation: 69663

You can do that by simply calling the remove method with an empty object.

yourDBCollection.remove(new BasicDBObject());

The equivalent Mongo shell command would be db.bios.remove({});

Remember that MongoDB query objects work like filters: They let anything through which doesn't explicitely violates them.

Upvotes: 1

Related Questions