我正在尝试使用Vertx MongoClient将新文档保存到MongoDB,如下所示:
MongoDBConnection.mongoClient.save("booking", query, res -> {
if(res.succeeded()) {
documentID = res.result();
System.out.println("MongoDB inserted successfully. + document ID is : " + documentID);
}
else {
System.out.println("MongoDB insertion failed.");
}
});
if(documentID != null) {
// MongoDB document insertion successful. Reply with a booking ID
String resMsg = "A confirmed booking has been successfully created with booking id as " + documentID +
". An email has also been triggered to the shared email id " + emailID;
documentID = null;
return new JsonObject().put("fulfillmentText", resMsg);
}
else {
// return intent response
documentID = null;
return new JsonObject().put("fulfillmentText",
"There is some issues while booking the shipment. Please start afreash.");
}
上面的代码成功地将查询jsonObject写入MongoDB集合。但是,包含此代码的函数始终以 返回 。bookingThere is some issues while booking the shipment. Please start afreash
发生这种情况可能是因为MongoClient处理程序“res”是异步的。但是,我想返回基于成功操作和失败保存操作的条件响应。save()save()
如何在Vertx Java中实现它?
幕布斯6054654
梵蒂冈之花
相关分类