Delete documents in MongoDB

2

I have a mongo database with a collection that has about 6,000,000 documents.

I would like to know how to delete all the documents without deleting the database or the collection.

I saw that with remove it can be done, but I doubt if with that command the collection is also deleted, because I do not want that to happen.

Use theft 3t.

    
asked by AnnaPS 13.08.2018 в 11:47
source

1 answer

3

I used deleteMany() :

db.coleccion.deleteMany({})

and deleted all documents without deleting the collection.

    
answered by 13.08.2018 / 12:05
source