![]() ![]() 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 Can I do it with remove? Well, I have tried: (key, limit = group_size - max_group_size, sort=) The MongoDB shell provides the following methods to delete documents from a collection: To delete multiple documents, use db.leteMany(). It does accept query, but mine include sorting and limiting. MongoDB Tutorial: Learn how to use different MongoDB delete functions, as well as MongoDB matching operators. 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 option is a document that specifies the deletion option.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. 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. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |