Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

MongoDB - How to delete documents which included in a list

$
0
0

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?


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>