Bhupi
Bhupi

Reputation: 395

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

Upvotes: 4

Views: 3964

Answers (1)

Branislav Lazic
Branislav Lazic

Reputation: 14806

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.

Upvotes: 7

Related Questions