Search in sources :

Example 1 with BulkWriteUpsert

use of com.mongodb.bulk.BulkWriteUpsert in project mongo-java-driver by mongodb.

the class WriteCommandResultHelper method getUpsertedItems.

@SuppressWarnings("unchecked")
private static List<BulkWriteUpsert> getUpsertedItems(final BsonDocument result) {
    BsonValue upsertedValue = result.get("upserted");
    if (upsertedValue == null) {
        return Collections.emptyList();
    } else {
        List<BulkWriteUpsert> bulkWriteUpsertList = new ArrayList<BulkWriteUpsert>();
        for (BsonValue upsertedItem : (BsonArray) upsertedValue) {
            BsonDocument upsertedItemDocument = (BsonDocument) upsertedItem;
            bulkWriteUpsertList.add(new BulkWriteUpsert(upsertedItemDocument.getNumber("index").intValue(), upsertedItemDocument.get("_id")));
        }
        return bulkWriteUpsertList;
    }
}
Also used : BulkWriteUpsert(com.mongodb.bulk.BulkWriteUpsert) BsonDocument(org.bson.BsonDocument) BsonArray(org.bson.BsonArray) ArrayList(java.util.ArrayList) BsonValue(org.bson.BsonValue)

Aggregations

BulkWriteUpsert (com.mongodb.bulk.BulkWriteUpsert)1 ArrayList (java.util.ArrayList)1 BsonArray (org.bson.BsonArray)1 BsonDocument (org.bson.BsonDocument)1 BsonValue (org.bson.BsonValue)1