Mongo Updates being super slow
Asked Answered
N

4

8

We are facing a timeout issue with our mongo updates. Our collection currently contains around 300 thousand documents. When we try to update a record via the UI, the server times out and the UI is stuck in limbo.

Lead.updateOne({
      _id: body.CandidateID
    }, {
      $set: {
        ingestionStatus: 'SUBMITTED',
        program: body.program,
        participant: body.participant,
        promotion: body.promotion,
        addressMeta: body.addressMeta,
        CreatedByID: body.CreatedByID,
        entryPerson: body.entryPerson,
        lastEnteredOn: body.lastEnteredOn,
        zipcode: body.zipcode,
        state: body.state,
        readableAddress: body.readableAddress,
        promotionId: body.promotionId,
        programId: body.programId,
        phone1: body.phone1,
        personId: body.personId,
        lastName: body.lastName,
        hasSignature: body.hasSignature,
        firstName: body.firstName,
        city: body.city,
        email: body.email,
        addressVerified: body.addressVerified,
        address: body.address,
        accountId: body.accountId
      }

This is how we update a single record. We are using mlab and Heroku in our stack. Looking for advice on how to speed this up considerably.

Thank you.

Nephew answered 25/2, 2019 at 19:49 Comment(1)
That is a very basic update that should complete in ms. Is there some other operation happening with the database that may be blocking the update?Compact
Y
3

If your indexes are fine then you could try rebuilding indexes on this collection. collection indexes from the mango command line: For example, rebuild the lead collection indexes from the mongo command line:

db.lead.reIndex();

Reference:

https://docs.mongodb.com/v3.2/tutorial/manage-indexes/ https://docs.mongodb.com/manual/reference/command/repairDatabase/

Yvoneyvonne answered 7/3, 2019 at 8:27 Comment(0)
G
1

if you are not using this then try this one Index builds can block write operations on your database, so you don’t want to build indexes in the foreground on large tables during peak usage. You can use the background creation of indexes by specifying background: true when creating.

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

This will ultimately take longer to complete, but it will not block operations and will have less of an impact on performance.

Geography answered 10/3, 2019 at 5:10 Comment(0)
H
1

1) Shard Lead collection by id as shard key. 2) Check if the memory taken by mongodb due to index is less than the memory of the mongoDb server.

Hannahhannan answered 10/3, 2019 at 11:52 Comment(0)
E
1

Have you tried what this answer suggests? Namely, updating with no write-concern?

Encapsulate answered 12/3, 2019 at 14:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.