I want to delete documents from a collection which are not included in a list with Python.All documents have a title field, and I have a list of the titles.
The list of titles is like below:
titles = ["title1", "title2", "title3"]
The documents in MongoDB are like below.
[ {"_id": { "$oid": "fsadkfds" },"title": "title1", }, {"_id": { "$oid": "fasd;jklfdsma" },"title": "title2", }, {"_id": { "$oid": "fdsjk" },"title": "title3", }, {"_id": { "$oid": "klfdsjsdksf" },"title": "title4", },]In this case, I want to delete documents that have the title: title1, title2, and title3. In other words, I want to keep only title4.
How could I achieve this?