is save method of MongoRepository does save document one by one or it uses the bulk insert feature of mongo . problem i am facing is , i am passing ist of 1000 documents to repository but nothing is changes in context of performance.
Interface MongoRepository<T,ID extends Serializable>
save
<S extends T> List<S> save(Iterable<S> entites)
Specified by:
save in interface CrudRepository<T,ID extends Serializable>
not sure what its super class crudrespository is doing as that is specific to JPA and not mongo
It uses bulk insert. Take for instance MongoRepository implementation - SimpleMongoRepository#save method. In case of insertion, it will invoke insertAll
from MongoOperations
and implementation of MongoOperations
is MongoTemplate
. And now you can take a look at MongoTemplate#insertAll and you will see it invokes MongoTemplate#doInsertAll which performs bulk insert by calling MongoTemplate#doInsertBatch method.
And yeah. Insertion of 1000 documents will probably not significantly reflect performance differences.
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