-
Notifications
You must be signed in to change notification settings - Fork 233
Mongo Batch Insert Update
Batch insert/update is an important feature keeping NOSQL and performance in mind.
##Feature Available
Along with MongoDB, this feature is also available for Cassandra and HBase from 2.1 onwards.
##How to Use ####Persistence.xml
Modify persistence.xml to add a property:
<property name="kundera.batch.size" value="5000" />
You can configure value as required batch size.
####Order of Bulk Operation
ORDERED: Requests included in the bulk operations will be executed in order and will halt on the first failure.
UNORDERED: Requests included in the bulk operation will be executed in an undefined order, and all requests will be executed even if some fail. Write requests included in the bulk operations will be executed in order
By default, Bulk Operation is UNORDERED in Kundera-MongoDB. But you can set this to ORDERED/UNORDERED using boolean true/false for a particular entityManager instance.
em = emf.createEntityManager();
em.setProperty(MongoDBClientProperties.ORDERED_BULK_OPERATION, true);
By default, WriteConcern is ACKNOWLEDGED. Additionally, you can also change write concern for a particular entityManager instance using:
em.setProperty(MongoDBClientProperties.WRITE_CONCERN, WriteConcern.UNACKNOWLEDGED);
####Flush Operation
Implicit flush: Based on configured value, Kundera will handle implicit flush upon reaching batch size value.
Explicit flush: You can flush explicitly, simply by invoking entitymanger.flush()
method.
##Under the Hood
Kundera uses methods of BulkWriteOperation
from Mongo Java Driver
to perform this bulk insert & update.
##Sample Example MongoBatchProcessorTest.