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.

aliirz
  • 1,008
  • 2
  • 13
  • 25
  • 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? – JohnnyHK Mar 10 '19 at 05:27

4 Answers4

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/

Thamaraiselvam
  • 6,961
  • 8
  • 45
  • 71
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.

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.

1

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

Zamfi
  • 327
  • 2
  • 9