How to delete data from MongoDB without slowing it to a stop?

Each time we remove large amounts of data from our MongoDB with collection.remove(), this makes the database so slow that ultimately our web servers go down. I believe this is because the delete operation blocks the collection for longer periods of time.

We have a request that gives us all the documents that we want to delete. However, the request does not include a date / time field, so we cannot use the TTL index.

Is there a way to delete data in a way nicethat blocks the lock from time to time?

+4
source share
1 answer

Using bulk operations

. bulk.find(queryDoc).remove() db.collection.remove(queryDoc), . :

var bulk = db.yourCollection.initializeUnorderedBulkOp()
bulk.find(yourQuery).remove()
bulk.execute()

. Bulk.find(). remove() MongoDB.

, . , db.collection.remove(query).

. 12M- 5- MacBook, , , 10 . , , .

, , , . , : , , . mongod , .

, , , .

db.collection.createIndex(
  {firstFieldYouQueryBy:1,...,NthFieldYouQueryBy:1},
  {background:true}
)

, . . , :

db.currentOp()

( ).

( db.collection.getIndices()), , , . , , , .

, .

, , .

+9

Source: https://habr.com/ru/post/1611580/


All Articles