List of usage examples for io.vertx.core.json JsonObject JsonObject
public JsonObject()
From source file:examples.MongoClientExamples.java
License:Open Source License
public void example5(MongoClient mongoClient) { // Match any documents with title=The Hobbit JsonObject query = new JsonObject().put("title", "The Hobbit"); // Set the author field JsonObject update = new JsonObject().put("$set", new JsonObject().put("author", "J. R. R. Tolkien")); mongoClient.updateCollection("books", query, update, res -> { if (res.succeeded()) { System.out.println("Book updated !"); } else {/* w ww . j a va 2 s.c om*/ res.cause().printStackTrace(); } }); }
From source file:examples.MongoClientExamples.java
License:Open Source License
public void example6(MongoClient mongoClient) { // Match any documents with title=The Hobbit JsonObject query = new JsonObject().put("title", "The Hobbit"); // Set the author field JsonObject update = new JsonObject().put("$set", new JsonObject().put("author", "J. R. R. Tolkien")); UpdateOptions options = new UpdateOptions().setMulti(true); mongoClient.updateCollectionWithOptions("books", query, update, options, res -> { if (res.succeeded()) { System.out.println("Book updated !"); } else {//from ww w. j a v a 2s. c o m res.cause().printStackTrace(); } }); }
From source file:examples.MongoClientExamples.java
License:Open Source License
public void example7(MongoClient mongoClient) { JsonObject query = new JsonObject().put("title", "The Hobbit"); JsonObject replace = new JsonObject().put("title", "The Lord of the Rings").put("author", "J. R. R. Tolkien"); mongoClient.replaceDocuments("books", query, replace, res -> { if (res.succeeded()) { System.out.println("Book replaced !"); } else {/* w ww .j a va 2 s.co m*/ res.cause().printStackTrace(); } }); }
From source file:examples.MongoClientExamples.java
License:Open Source License
public void example8(MongoClient mongoClient) { // empty query = match any JsonObject query = new JsonObject(); mongoClient.find("books", query, res -> { if (res.succeeded()) { for (JsonObject json : res.result()) { System.out.println(json.encodePrettily()); }//from w w w . j av a 2 s . co m } else { res.cause().printStackTrace(); } }); }
From source file:examples.MongoClientExamples.java
License:Open Source License
public void example9(MongoClient mongoClient) { // will match all Tolkien books JsonObject query = new JsonObject().put("author", "J. R. R. Tolkien"); mongoClient.find("books", query, res -> { if (res.succeeded()) { for (JsonObject json : res.result()) { System.out.println(json.encodePrettily()); }/*from w w w.java2s . c o m*/ } else { res.cause().printStackTrace(); } }); }
From source file:examples.MongoClientExamples.java
License:Open Source License
public void findBatch(MongoClient mongoClient) { // will match all Tolkien books JsonObject query = new JsonObject().put("author", "J. R. R. Tolkien"); mongoClient.findBatch("book", query).exceptionHandler(throwable -> throwable.printStackTrace()) .endHandler(v -> System.out.println("End of research")) .handler(doc -> System.out.println("Found doc: " + doc.encodePrettily())); }
From source file:examples.MongoClientExamples.java
License:Open Source License
public void findBatchWithOptions(MongoClient mongoClient) { // will match all Tolkien books JsonObject query = new JsonObject().put("author", "J. R. R. Tolkien"); FindOptions options = new FindOptions().setBatchSize(100); mongoClient.findBatchWithOptions("book", query, options) .exceptionHandler(throwable -> throwable.printStackTrace()) .endHandler(v -> System.out.println("End of research")) .handler(doc -> System.out.println("Found doc: " + doc.encodePrettily())); }
From source file:examples.MongoClientExamples.java
License:Open Source License
public void example10(MongoClient mongoClient) { JsonObject query = new JsonObject().put("author", "J. R. R. Tolkien"); mongoClient.removeDocuments("books", query, res -> { if (res.succeeded()) { System.out.println("Never much liked Tolkien stuff!"); } else {/*from w ww. j a v a 2s . c o m*/ res.cause().printStackTrace(); } }); }
From source file:examples.MongoClientExamples.java
License:Open Source License
public void example11(MongoClient mongoClient) { JsonObject query = new JsonObject().put("author", "J. R. R. Tolkien"); mongoClient.count("books", query, res -> { if (res.succeeded()) { long num = res.result(); } else {//from w w w .j a v a 2s . c o m res.cause().printStackTrace(); } }); }
From source file:examples.MongoClientExamples.java
License:Open Source License
public void example12(MongoClient mongoClient) { JsonObject command = new JsonObject().put("aggregate", "collection_name").put("pipeline", new JsonArray()); mongoClient.runCommand("aggregate", command, res -> { if (res.succeeded()) { JsonArray resArr = res.result().getJsonArray("result"); // etc } else {//from ww w . j av a2 s. c o m res.cause().printStackTrace(); } }); }