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.
NoSQL databases like MongoDB are often structured without a schema to make writes convenient, and it's a key part what also makes them so unique and popular. However, the lack of a schema can dramatically slows down reads, causing problems with query performance as your application scales.
Mongodb Update opearation takes long time to insert new array filed in the existing collection documents. Save this question. Show activity on this post. Above update takes around 2 minutes to update the entire collection.Is there any other way to optimize this update query.
Like remove() , the update() function is deprecated in favor of the more explicit updateOne() , updateMany() , and replaceOne() functions. You should replace update() with updateOne() , unless you use the multi or overwrite options.
MongoDB Update method is used to update the document from the collection, and the update method will update the value of the existing document. We have used a $set operator at the time of updating the document. We can update a single document by using an update or updateOne method.
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/
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) 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With