本文整理了Java中io.vertx.ext.mongo.MongoClient.find()
方法的一些代码示例,展示了MongoClient.find()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MongoClient.find()
方法的具体详情如下:
包路径:io.vertx.ext.mongo.MongoClient
类名称:MongoClient
方法名:find
暂无
代码示例来源:origin: vert-x3/vertx-examples
private void listAlbums(Message<JsonObject> msg) {
// issue a find command to mongo to fetch all documents from the "albums" collection.
mongo.find("albums", new JsonObject(), lookup -> {
// error handling
if (lookup.failed()) {
msg.fail(500, lookup.cause().getMessage());
return;
}
// now convert the list to a JsonArray because it will be easier to encode the final object as the response.
final JsonArray json = new JsonArray();
for (JsonObject o : lookup.result()) {
json.add(o);
}
msg.reply(json);
});
}
代码示例来源:origin: vert-x3/vertx-examples
mongo.find("users", new JsonObject(), lookup -> {
代码示例来源:origin: vert-x3/vertx-examples
System.out.println("Inserted id: " + id.result());
mongoClient.find("products", new JsonObject().put("itemId", "12345"), res -> {
System.out.println("Name is " + res.result().get(0).getString("name"));
代码示例来源:origin: vert-x3/vertx-examples
List<JsonObject> results = awaitResult(h -> mongo.find("users", new JsonObject(), h));
System.out.println("Retrieved " + results.size() + " results");
代码示例来源:origin: vert-x3/vertx-examples
mongo.find("users", new JsonObject(), lookup -> {
代码示例来源:origin: io.vertx/vertx-rx-java
/**
* Find matching documents in the specified collection
* @param collection the collection
* @param query query used to match documents
* @param resultHandler will be provided with list of documents
* @return
*/
public io.vertx.rxjava.ext.mongo.MongoClient find(String collection, JsonObject query, Handler<AsyncResult<List<JsonObject>>> resultHandler) {
delegate.find(collection, query, resultHandler);
return this;
}
代码示例来源:origin: io.vertx/vertx-mongo-service
@Override
public MongoService find(String collection, JsonObject query, Handler<AsyncResult<List<JsonObject>>> resultHandler) {
client.find(collection, query, resultHandler);
return this;
}
代码示例来源:origin: vert-x3/vertx-rx
/**
* Find matching documents in the specified collection
* @param collection the collection
* @param query query used to match documents
* @param resultHandler will be provided with list of documents
* @return
*/
public io.vertx.rxjava.ext.mongo.MongoClient find(String collection, JsonObject query, Handler<AsyncResult<List<JsonObject>>> resultHandler) {
delegate.find(collection, query, resultHandler);
return this;
}
代码示例来源:origin: cescoffier/vertx-workshop
public void getPlacesForCategory(String category,
Handler<AsyncResult<List<Place>>> resultHandler) {
mongo.find(COLLECTION,
new JsonObject().put("category", category),
ar -> {
if (ar.failed()) {
resultHandler.handle(Future.failedFuture(ar.cause()));
} else {
List<Place> places = ar.result().stream()
.map(Place::new).collect(Collectors.toList());
resultHandler.handle(Future.succeededFuture(places));
}
}
);
}
代码示例来源:origin: cescoffier/my-vertx-first-app
private void getAll(RoutingContext routingContext) {
mongo.find(COLLECTION, new JsonObject(), results -> {
List<JsonObject> objects = results.result();
List<Whisky> whiskies = objects.stream().map(Whisky::new).collect(Collectors.toList());
routingContext.response()
.putHeader("content-type", "application/json; charset=utf-8")
.end(Json.encodePrettily(whiskies));
});
}
代码示例来源:origin: io.vertx/vertx-lang-groovy
public static io.vertx.ext.mongo.MongoClient find(io.vertx.ext.mongo.MongoClient j_receiver, java.lang.String collection, java.util.Map<String, Object> query, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.List<java.util.Map<String, Object>>>> resultHandler) {
io.vertx.core.impl.ConversionHelper.fromObject(j_receiver.find(collection,
query != null ? io.vertx.core.impl.ConversionHelper.toJsonObject(query) : null,
resultHandler != null ? new io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.List<io.vertx.core.json.JsonObject>>>() {
public void handle(io.vertx.core.AsyncResult<java.util.List<io.vertx.core.json.JsonObject>> ar) {
resultHandler.handle(ar.map(event -> event != null ? event.stream().map(elt -> io.vertx.core.impl.ConversionHelper.fromJsonObject(elt)).collect(java.util.stream.Collectors.toList()) : null));
}
} : null));
return j_receiver;
}
public static io.vertx.core.streams.ReadStream<io.vertx.core.json.JsonObject> findBatch(io.vertx.ext.mongo.MongoClient j_receiver, java.lang.String collection, java.util.Map<String, Object> query) {
代码示例来源:origin: io.vertx/vertx-auth-mongo
@Override
public void authenticate(JsonObject authInfo, Handler<AsyncResult<User>> resultHandler) {
String username = authInfo.getString(this.usernameCredentialField);
String password = authInfo.getString(this.passwordCredentialField);
// Null username is invalid
if (username == null) {
resultHandler.handle((Future.failedFuture("Username must be set for authentication.")));
return;
}
if (password == null) {
resultHandler.handle((Future.failedFuture("Password must be set for authentication.")));
return;
}
AuthToken token = new AuthToken(username, password);
JsonObject query = createQuery(username);
mongoClient.find(this.collectionName, query, res -> {
try {
if (res.succeeded()) {
User user = handleSelection(res, token);
resultHandler.handle(Future.succeededFuture(user));
} else {
resultHandler.handle(Future.failedFuture(res.cause()));
}
} catch (Throwable e) {
log.warn(e);
resultHandler.handle(Future.failedFuture(e));
}
});
}
代码示例来源:origin: folio-org/okapi
public void getAll(Class<T> clazz, Handler<ExtendedAsyncResult<List<T>>> fut) {
final String q = "{}";
JsonObject jq = new JsonObject(q);
cli.find(collection, jq, res -> {
if (res.failed()) {
fut.handle(new Failure<>(INTERNAL, res.cause()));
} else {
List<JsonObject> resl = res.result();
List<T> ml = new LinkedList<>();
for (JsonObject jo : resl) {
decode(jo);
T env = Json.decodeValue(jo.encode(), clazz);
ml.add(env);
}
fut.handle(new Success<>(ml));
}
});
}
代码示例来源:origin: folio-org/okapi
@Override
public void updateModules(String id, SortedMap<String, Boolean> enabled, Handler<ExtendedAsyncResult<Void>> fut) {
JsonObject jq = new JsonObject().put("_id", id);
cli.find(COLLECTION, jq, gres -> {
if (gres.failed()) {
logger.debug("disableModule: find failed: " + gres.cause().getMessage());
fut.handle(new Failure<>(INTERNAL, gres.cause()));
} else {
List<JsonObject> l = gres.result();
if (l.isEmpty()) {
logger.debug("disableModule: not found: " + id);
fut.handle(new Failure<>(NOT_FOUND, messages.getMessage("1100", id)));
} else {
JsonObject d = l.get(0);
final Tenant t = decodeTenant(d);
t.setEnabled(enabled);
JsonObject document = encodeTenant(t, id);
cli.save(COLLECTION, document, sres -> {
if (sres.failed()) {
logger.debug("TenantStoreMongo: disable: saving failed: " + sres.cause().getMessage());
fut.handle(new Failure<>(INTERNAL, sres.cause()));
} else {
fut.handle(new Success<>());
}
});
}
}
});
}
代码示例来源:origin: folio-org/okapi
final String id = td.getId();
JsonObject jq = new JsonObject().put("_id", id);
cli.find(COLLECTION, jq, res
-> {
if (res.failed()) {
代码示例来源:origin: io.vertx/vertx-auth-mongo
private boolean verifyUserData() throws Exception {
final StringBuffer buffer = new StringBuffer();
CountDownLatch intLatch = new CountDownLatch(1);
String collectionName = authProvider.getCollectionName();
log.info("verifyUserData in " + collectionName);
getMongoClient().find(collectionName, new JsonObject(), res -> {
if (res.succeeded()) {
log.info(res.result().size() + " users found: " + res.result());
} else {
log.error("", res.cause());
buffer.append("false");
}
intLatch.countDown();
});
awaitLatch(intLatch);
return buffer.length() == 0;
}
内容来源于网络,如有侵权,请联系作者删除!