Example usage for com.mongodb InsertOptions InsertOptions

List of usage examples for com.mongodb InsertOptions InsertOptions

Introduction

In this page you can find the example usage for com.mongodb InsertOptions InsertOptions.

Prototype

InsertOptions

Source Link

Usage

From source file:com.ikanow.aleph2.shared.crud.mongodb.services.MongoDbCrudService.java

License:Apache License

public CompletableFuture<Tuple2<Supplier<List<Object>>, Supplier<Long>>> storeObjects(final List<O> new_objects,
        final boolean replace_if_present) {
    if (replace_if_present) {
        // This is an "illegal arg exception" so throw immediately
        throw new RuntimeException(ErrorUtils.BULK_REPLACE_DUPLICATES_NOT_SUPPORTED);
    }/*from   w w  w.  j av a 2s.  c  o m*/
    try {
        final List<DBObject> l = new_objects.stream().map(o -> convertToBson(o)).collect(Collectors.toList());

        final com.mongodb.WriteResult orig_result = _state.orig_coll.insert(l,
                Patterns.match(_state.orig_coll).<InsertOptions>andReturn().when(FongoDBCollection.class,
                        () -> new InsertOptions().continueOnError(true).writeConcern(new WriteConcern()))
                        .otherwise(() -> new InsertOptions().continueOnError(true)));

        return CompletableFuture.completedFuture(
                Tuples._2T(() -> l.stream().map(o -> (Object) _state.coll.convertFromDbId(o.get(_ID)))
                        .collect(Collectors.toList()), () -> {
                            return Patterns.match(_state.orig_coll).<Long>andReturn()
                                    .when(FongoDBCollection.class, () -> (Long) (long) orig_result.getN())
                                    .otherwise(__ -> (long) l.size());
                        }));
    } catch (Exception e) {
        return FutureUtils.<Tuple2<Supplier<List<Object>>, Supplier<Long>>>returnError(e);
    }
}

From source file:mvm.rya.mongodb.MongoDBRyaDAO.java

License:Apache License

public void add(Iterator<RyaStatement> statement) throws RyaDAOException {
    List<DBObject> dbInserts = new ArrayList<DBObject>();
    while (statement.hasNext()) {
        RyaStatement ryaStatement = statement.next();
        DBObject insert = storageStrategy.serialize(ryaStatement);
        dbInserts.add(insert);//from   w ww  .  j  av a2s.com

        try {
            for (RyaSecondaryIndexer index : secondaryIndexers) {
                index.storeStatement(ryaStatement);
            }
        } catch (IOException e) {
            throw new RyaDAOException(e);
        }

    }
    coll.insert(dbInserts, new InsertOptions().continueOnError(true));
}

From source file:org.apache.rya.mongodb.batch.collection.DbCollectionType.java

License:Apache License

@Override
public void insertMany(final List<DBObject> items) {
    collection.insert(items, new InsertOptions().continueOnError(true));
}