Announcement Announcement Module
Collapse
No announcement yet.
mongodb: how to remove all data from collection? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • mongodb: how to remove all data from collection?

    I need to remove all the data from certain collection.

    anybody knows how to perform this line using mongoTemplate:

    Code:
    >db.myCollection.remove({});
    i know there's a remove method but it needs a query, and i dont know how to create an empty query that selects all the documents in the collection.

    is it ok to call:
    Code:
    mongoTemplate.dropCollection("myCollection");

  • #2
    Code:
    mongoTemplate.remove(new Query(), "collectionName");
    is the simplest way.

    Comment

    Working...
    X