MongoDB Bulk operations performance is slow for Updates

15 views
Skip to first unread message

Eresh G

unread,
Dec 24, 2019, 10:08:50 AM12/24/19
to mongodb-dev
I am new to Mongo. I was playing around with Spring Boot MongoRepositories and MongoTemplate. For this I did some sample application. Please find code from GIT Repository here

For this use case I have inserted 5000 randomly generated data and inserted in my Mongo Local instance. I tested inserting data using repository.saveAll() and batch update of Mongo Template

Document document = new Document();
generateUserDetailsDocument
(details, document);
documents
.add(new InsertOneModel<>(document));

The average time for above use cases are

Repository -- 4.5 seconds, which is large compared to RDBMS.
MongoTemplate -- 3.5 seconds, which is large compared to RDBMS.
Now I tried with update data, for this case I loaded top 5000 records and for each record updated one of the property values and tried to repeat the same process.

Repository -- saveAll(). and for Mongo Template

   
Document document = new Document();
generateUserDetailsDocument
(details, document);
UpdateOptions updateOptions = new UpdateOptions();
updateOptions
.upsert(true);
documents
.add(new ReplaceOneModel<>(new Document("_id", details.getId()), document));
userDetailsMongoCollection.bulkWrite(documents, new BulkWriteOptions().ordered(false));

Now I could see very huge difference in time

Repository -- 10 seconds, High compared to RDBMS.
Mongo Template -- 30 seconds, Very high compare to the above case.
Do NOsql inserts take more time compare to RDBMS? Is it related to the collection structure? How to improve the above case for high performance. I followed the latest documentation from Mongo official site.

Any help is highly appreciated.

regards Eresh
Reply all
Reply to author
Forward
0 new messages