'Deletion Operation in AWS DocumentDB

I have a question about deleting data in AWS DocumentDB.

I am using PuTTY to connect to EC2 instance and I use mongo shell command to connect with my Document DB.

I checked AWS DocumentDB documentation but I couldn't find how to delete singular data or whole data in one collection. For example I say:

rs0:PRIMARY> show databases
gg_events_document_db  0.000GB
rs0:PRIMARY> use gg_events_document_db
switched to db gg_events_document_db
rs0:PRIMARY> db.data_collection.find({"Type": "15"})
{"Type" : "15", "Humidity" : "14.3%"}

Now I have found the data and I want to delete it. What query should I need to run?

Or what if I want to delete all data in the collection? Without deleting my collection how can I do it?

Probably I am asking very basic questions but I couldn't find a query like this on my own.

I would be so happy if some experienced people in AWS DocumentDB can help me or share some resources.

Thanks a lot 🙌



Solution 1:[1]

To delete a single document matching a filter, you would use the deleteOne() method. For example, for your case that would be:

db.data_collection.deleteOne({"Type": "15"})

To delete all documents matching the filter, then use deleteMany().

There's also remove() method, but it was deprecated.

The drop() method deletes the entire collection.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mihai A