private void loadData(MongoClient db) { db.dropCollection("users", drop -> { if (drop.failed()) { throw new RuntimeException(drop.cause()); } List<JsonObject> users = new LinkedList<>(); users.add(new JsonObject() .put("username", "pmlopes") .put("firstName", "Paulo") .put("lastName", "Lopes") .put("address", "The Netherlands")); users.add(new JsonObject() .put("username", "timfox") .put("firstName", "Tim") .put("lastName", "Fox") .put("address", "The Moon")); for (JsonObject user : users) { db.insert("users", user, res -> { System.out.println("inserted " + user.encode()); }); } }); } }
private void loadData(MongoClient db) { db.dropCollection("albums", drop -> { if (drop.failed()) { throw new RuntimeException(drop.cause());
/** * Drop a collection * @param collection the collection * @param resultHandler will be called when complete * @return */ public io.vertx.rxjava.ext.mongo.MongoClient dropCollection(String collection, Handler<AsyncResult<Void>> resultHandler) { delegate.dropCollection(collection, resultHandler); return this; }
@Override public MongoService dropCollection(String collection, Handler<AsyncResult<Void>> resultHandler) { client.dropCollection(collection, resultHandler); return this; }
/** * Drop a collection * @param collection the collection * @param resultHandler will be called when complete * @return */ public io.vertx.rxjava.ext.mongo.MongoClient dropCollection(String collection, Handler<AsyncResult<Void>> resultHandler) { delegate.dropCollection(collection, resultHandler); return this; }
public void init(boolean reset, Handler<ExtendedAsyncResult<Void>> fut) { if (!reset) { fut.handle(new Success<>()); } else { cli.dropCollection(collection, res -> { if (res.failed()) { fut.handle(new Failure<>(INTERNAL, res.cause())); } else { fut.handle(new Success<>()); } }); } }
/** * Method drops all collections which are starting with the prefix {@link #TABLE_PREFIX} * * @param latch * the latch to be used */ protected void dropCollections(CountDownLatch latch) { // Drop all the collections in the db mongoClient.getCollections(onSuccess(list -> { AtomicInteger collCount = new AtomicInteger(); List<String> toDrop = getOurCollections(list); int count = toDrop.size(); if (!toDrop.isEmpty()) { for (String collection : toDrop) { mongoClient.dropCollection(collection, onSuccess(v -> { if (collCount.incrementAndGet() == count) { latch.countDown(); } })); } } else { latch.countDown(); } })); }