Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb 在完成多个异步查询后运行查询_Mongodb_Java 8_Vert.x - Fatal编程技术网

Mongodb 在完成多个异步查询后运行查询

Mongodb 在完成多个异步查询后运行查询,mongodb,java-8,vert.x,Mongodb,Java 8,Vert.x,我正在使用Vertex mongoclient,代码如下: mongoClient.getCollections(res -> { if (res.succeeded()) { if (res.result().size() > 0) { for (String collection : res.result()) { mongoClient.dropCollection(

我正在使用Vertex mongoclient,代码如下:

mongoClient.getCollections(res -> {
        if (res.succeeded()) {
            if (res.result().size() > 0) {
                for (String collection : res.result()) {
                    mongoClient.dropCollection(collection, resDrop -> {
                        if (resDrop.succeeded()) {
                            LOGGER.warn(collection + "was dropped");
                        }
                    });
                }
            } else LOGGER.warn("database was dropped");
        } else LOGGER.warn("database was dropped");
    });
我想在删除所有旧集合后创建一些新集合
但正如我们所知,删除集合是异步执行的 我如何确定所有旧收藏何时都已删除?

这是一个常见问题。请查看Vert.x文档中的部分。

这是一个常见问题。请查看Vert.x文档中的部分。

我建议使用。您可以调用该方法。

我建议使用。您可以调用该方法。

mongoClient.getCollections(res->{
如果(res.successed()){
如果(res.result().size()>0){
**List futureList=新建ArrayList();**
对于(字符串集合:res.result()){
mongoClient.dropCollection(collection,resDrop->{
if(resDrop.successed()){
**Future=Future.Future();
添加(未来);
future.complete()**
LOGGER.warn(收集+“已删除”);
}否则{
未来失败(ar.cause());
}
});
}
**CompositeFuture.all(futureList).setHandler(ar->{
如果(ar.successed()){
LOGGER.info(“已删除所有集合”);
}否则{
LOGGER.warn(“未删除一个或所有集合”);
}
});**
}else LOGGER.warn(“数据库已删除”);
}else LOGGER.warn(“数据库已删除”);
});
mongoClient.getCollections(res->{
如果(res.successed()){
如果(res.result().size()>0){
**List futureList=新建ArrayList();**
对于(字符串集合:res.result()){
mongoClient.dropCollection(collection,resDrop->{
if(resDrop.successed()){
**Future=Future.Future();
添加(未来);
future.complete()**
LOGGER.warn(收集+“已删除”);
}否则{
未来失败(ar.cause());
}
});
}
**CompositeFuture.all(futureList).setHandler(ar->{
如果(ar.successed()){
LOGGER.info(“已删除所有集合”);
}否则{
LOGGER.warn(“未删除一个或所有集合”);
}
});**
}else LOGGER.warn(“数据库已删除”);
}else LOGGER.warn(“数据库已删除”);
});

为什么不在一个命令中销毁所有集合?选中此项这只是为了测试我需要此项在完成多个异步查询后运行查询使用completablefuture或RxJava使用
CountdownLatch
和要删除的集合数。收集丢弃成功时的倒计时(),然后使用.awat()它等待所有操作执行完毕,然后执行您的内容。为什么不在一个命令中销毁所有集合?选中此项这只是为了测试我需要此项在完成多个异步查询后运行查询使用completablefuture或RxJava使用
CountdownLatch
和要删除的集合数。收集丢弃成功时的倒计时(),然后使用.awat()它等待所有操作执行完毕,然后执行您的内容。也
mongoClient.getCollections(res -> {
        if (res.succeeded()) {
            if (res.result().size() > 0) {
                **List<Future> futureList  = new ArrayList<>();** 
                for (String collection : res.result()) {
                    mongoClient.dropCollection(collection, resDrop -> {
                        if (resDrop.succeeded()) {
                            **Future future = Future.future();
                            futureList.add(future);
                            future.complete();**
                            LOGGER.warn(collection + "was dropped");
                        }else{
                          future.fail(ar.cause());  
                       }

                    });
                }

               **CompositeFuture.all(futureList).setHandler(ar -> {
                    if (ar.succeeded()) {
                        LOGGER.info("All collections was dropped");
                    } else {
                        LOGGER.warn("One or all collections was not dropped");
                    }
                });**
            } else LOGGER.warn("database was dropped");
        } else LOGGER.warn("database was dropped");
    });