Package com.mongodb

Examples of com.mongodb.BulkWriteOperation


        final AtomicBoolean cancelCondition = new AtomicBoolean();

        List<ObjectId> ids = Lists.newArrayListWithCapacity(bulkSize);
        List<Future<?>> runningTasks = new ArrayList<Future<?>>(maxRunningTasks);

        BulkWriteOperation bulkOperation = collection.initializeOrderedBulkOperation();
        try {
            while (objects.hasNext()) {
                RevObject object = objects.next();
                bulkOperation.insert(toDocument(object));

                ids.add(object.getId());

                if (ids.size() == bulkSize || !objects.hasNext()) {
                    InsertTask task = new InsertTask(bulkOperation, listener, ids, cancelCondition);
View Full Code Here


        // Count all documents in a collection but take a maximum second to do so
        coll.find().maxTime(1, SECONDS).count();

        // Bulk operations
        BulkWriteOperation builder = coll.initializeOrderedBulkOperation();
        builder.insert(new BasicDBObject("_id", 1));
        builder.insert(new BasicDBObject("_id", 2));
        builder.insert(new BasicDBObject("_id", 3));

        builder.find(new BasicDBObject("_id", 1)).updateOne(new BasicDBObject("$set", new BasicDBObject("x", 2)));
        builder.find(new BasicDBObject("_id", 2)).removeOne();
        builder.find(new BasicDBObject("_id", 3)).replaceOne(new BasicDBObject("_id", 3).append("x", 4));

        BulkWriteResult result = builder.execute();
        System.out.println("Ordered bulk write result : " + result);

        // Unordered bulk operation - no guarantee of order of operation
        builder = coll.initializeUnorderedBulkOperation();
        builder.find(new BasicDBObject("_id", 1)).removeOne();
        builder.find(new BasicDBObject("_id", 2)).removeOne();

        result = builder.execute();
        System.out.println("Ordered bulk write result : " + result);

        // parallelScan
        ParallelScanOptions parallelScanOptions = ParallelScanOptions
                .builder()
View Full Code Here

    private <T> Iterable<Key<T>> insert(final DBCollection dbColl, final Iterable<T> entities, final WriteConcern wc) {
        WriteConcern writeConcern = wc;
        final List<Key<T>> savedKeys = new ArrayList<Key<T>>();
        if (morphia.getUseBulkWriteOperations()) {
            BulkWriteOperation bulkWriteOperation = dbColl.initializeOrderedBulkOperation();
            final Map<Object, DBObject> involvedObjects = new LinkedHashMap<Object, DBObject>();
            for (final T entity : entities) {
                if (writeConcern == null) {
                    writeConcern = getWriteConcern(entity);
                }
                DBObject dbObj = toDbObject(entity, involvedObjects);
                bulkWriteOperation.insert(dbObj);
                savedKeys.add(postSaveGetKey(entity, dbObj, dbColl, new LinkedHashMap<Object, DBObject>()));
            }
            bulkWriteOperation.execute(writeConcern);
            postSaveOperations(involvedObjects);

        } else {
            writeConcern = getWriteConcern(entities.iterator().next());
            final List<DBObject> list = new ArrayList<DBObject>();
View Full Code Here

TOP

Related Classes of com.mongodb.BulkWriteOperation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.