Guest User

Untitled

a guest
Oct 1st, 2019
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. class Description{
  2.             private String code;
  3.  
  4.             public String getCode() {
  5.                 return code;
  6.             }
  7.  
  8.             public void setCode(String code) {
  9.                 this.code = code;
  10.             }
  11.         }
  12.  
  13.         BulkOperations bulkOperations = mongoTemplate.bulkOps(BulkOperations.BulkMode.UNORDERED, getCollectionName());
  14.  
  15.         Description d = new Description();
  16.         d.setCode("no");
  17.  
  18.         Query query = new Query(Criteria.where("code").is(d.getCode()));
  19.  
  20.         Document doc = new Document(); // org.bson.Document
  21.         mongoTemplate.getConverter().write(d, doc);
  22.         Update update = Update.fromDocument(doc);
  23.         System.out.println(update.toString());
  24.         bulkOperations.upsert(query, update);
  25.         bulkOperations.execute();
  26. }
Add Comment
Please, Sign In to add comment