-
Notifications
You must be signed in to change notification settings - Fork 233
Mongo Batch Insert Update
Batch insert/update is an important feature keeping use cases of NoSQL and system's performance in mind.
MongoDB, from version 2.6 has native support available for performing bulk operations. Kundera also enabled this support via its kundera-mongo module.
Modify persistence.xml to add a property:
<property name="kundera.batch.size" value="5000" />
You can configure value as required batch size.
MongoDB categorizes Bulk operations as :
ORDERED: In which requests included in the bulk operations will be executed in order and will halt on the first failure.
UNORDERED: The 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 operations are un-ordered via Kundera-MongoDB . But you can modify this by changing the value of this simple property ORDERED/UNORDERED using boolean true/false for a particular entityManager instance.
em = emf.createEntityManager();
em.setProperty(MongoDBClientProperties.ORDERED_BULK_OPERATION, true);
Also, by default, operations in MongoDB will be performed with ACKNOWLEDGED WriteConcern. However, you can also change write concern for a particular entityManager instance using:
em.setProperty(MongoDBClientProperties.WRITE_CONCERN, WriteConcern.UNACKNOWLEDGED);
Kundera uses methods of BulkWriteOperation
from Mongo Java Driver
to perform this bulk insert & update.