Örnek
Şöyle yaparız
@RequiredArgsConstructor
@Slf4j
public class PhishDetailsWriter extends MongoItemWriter<PhishDetailsDto> {
private final MongoTemplate mongoTemplate;
@Override
protected void doWrite(Chunk<? extends PhishDetailsDto> chunk) {
log.info("Writing chunk of size: {}", chunk.size());
BulkOperations bulkOps = mongoTemplate.bulkOps(BulkOperations.BulkMode.UNORDERED,
"domains");
for (PhishDetailsDto item : chunk) {
Query query = new Query(Criteria.where("domain").is(item.getDomain()));
Update update = new Update().addToSet("urls").each(item.getUrls());
bulkOps.upsert(query, update);
}
bulkOps.execute();
}
}
Hiç yorum yok:
Yorum Gönder