Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring data mongo db repository save

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

like image 798
Bhupi Avatar asked Mar 15 '23 03:03

Bhupi


1 Answers

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.

like image 155
Branislav Lazic Avatar answered Mar 17 '23 16:03

Branislav Lazic