![]() ![]() Now, I hope I have provided enough context and (hopefully) have restored my lost honour. Needless to say, that the foreach-found-remove approach works and yields the expected results. ![]() Moreover, it seems to screw mongo.Observe: C:\dev\poc\SDR>python FilterOoklaData.pyīad offset:0 accessing file: /data/db/ookla.0 - consider repairing database The following snippet deletes all documents in the items collection. Can I do it with remove? Well, I have tried: (key, limit = group_size - max_group_size, sort=) You can delete multiple items from a collection using the leteMany() action. It does accept query, but mine include sorting and limiting. Now, about the collection remove command. So, the last two steps are foreach-found-remove and this is the important detail of my question, that changes everything and I had to be more specific about it - sorry. Query the data by key, while sorting it ascending by the timestamp (the oldest first) and limiting the result to the count - max_group_size oldest recordsĪs you can see, this accomplishes the task of reducing the duplicates to at most N newest records.Iterate over all the pairs with count > max_group_size.So, what does it do? It reduces the number of duplicate keys to at most max_group_size per key value, leaving only the newest records. In MongoDB, if you need to delete a document in the mongo shell, you can use: The db.collection.remove () method The delete command The db.leteOne () method The db.leteMany () method This article provides examples of each. query the original collection by the entry key, order it by test_date ascending, limit to the group size minus max_group_size.įor id in (key, limit = group_size - max_group_size, **deleteFindArgs): Right now, I remove them manually, like this (using python): for id in mycoll.find(query, fields=): I have a query, which selects documents to be removed. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |