Deletion Operation in AWS DocumentDB

2.3k views Asked by At

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

2

There are 2 answers

1
herbertgoto On BEST ANSWER

Amazon DocumentDB has compatibility with MongoDB APIs for 3.6 and 4.0. This said, the same APIs can be used for this need. With respect to:

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

Yo can use:

db.data_collection.drop()

0
Mihai A On

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.