简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM