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;
}
}
Aggregations