我对Mongodb的java驱动程序很困惑.阅读官方文档似乎可以使用普通的MondoDB驱动程序或MongoDB异步驱动程序.
第一个问题是:我可以在同一个应用程序中使用它们,还是必须选择一个?
尝试使用Async驱动程序我发现了我以前做的事情(使用正常的驱动程序),现在我有点迷失了.例如,我曾经这样做:
FindIterable<Document> iterable = db.getCollection("my_coll").find(query);
String json = JSON.serialize(iterable);
Run Code Online (Sandbox Code Playgroud)
现在我真的不知道如何将结果转换为json字符串,因为它们没有包含JSONAsync驱动程序中的类.第二个问题:如果我不能同时使用两个驱动程序,那我怎么能序列化一个FindIterable<Document>?
有没有办法知道特定索引是在哪个 Elasticsearch 版本中创建的?
当您想要升级集群并且可能需要在升级集群之前将较旧的索引重新索引到较新的版本以避免不兼容问题时,这主要有用。
例如,如果我们要升级到7.5版本,如果我们有在5.x或更早版本中创建的索引,则需要在升级到7.5.0之前重新索引或删除它们。如果存在不兼容的索引,Elasticsearch 节点将无法启动。5.x 或更早版本索引的快照无法恢复到 7.x 集群,即使它们是由 6.x 集群创建的 ( https://www.elastic.co/guide/en/elasticsearch/reference/current/reindex -upgrade.html)。
我有一个webapp,我必须将结果从mongodb find()返回到我的java后端的前端.我正在使用Async Java驱动程序,我认为我必须从mongo返回结果的唯一方法是这样的:
public String getDocuments(){
...
collection.find(query).map(Document::toJson)
.into(new HashSet<String>(), new SingleResultCallback<HashSet<String>>() {
@Override
public void onResult(HashSet<String> strings, Throwable throwable) {
// here I have to get all the Json Documents in the set,
// make a whole json string and wake the main thread
}
});
// here I have to put the main thread to wait until I get the data in
// the onResult() method so I can return the string back to the front-end
...
return …Run Code Online (Sandbox Code Playgroud)