本文整理了Java中io.vertx.ext.mongo.MongoClient.insert()
方法的一些代码示例,展示了MongoClient.insert()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MongoClient.insert()
方法的具体详情如下:
包路径:io.vertx.ext.mongo.MongoClient
类名称:MongoClient
方法名:insert
暂无
代码示例来源:origin: vert-x3/vertx-examples
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());
});
}
});
}
}
代码示例来源:origin: vert-x3/vertx-examples
db.insert("albums", album, res -> {
System.out.println("inserted " + album.encode());
});
代码示例来源:origin: vert-x3/vertx-examples
String id = awaitResult(h -> mongo.insert("users", user, h));
System.out.println("Inserted id is " + id);
代码示例来源:origin: vert-x3/vertx-examples
mongo.insert("users", user, lookup -> {
代码示例来源:origin: vert-x3/vertx-examples
mongo.insert("users", newUser, insert -> {
代码示例来源:origin: io.vertx/vertx-mongo-service
@Override
public MongoService insert(String collection, JsonObject document, Handler<AsyncResult<String>> resultHandler) {
client.insert(collection, document, resultHandler);
return this;
}
代码示例来源:origin: io.vertx/vertx-rx-java
/**
* Insert a document in the specified collection
* <p>
* This operation might change <i>_id</i> field of <i>document</i> parameter
* @param collection the collection
* @param document the document
* @param resultHandler result handler will be provided with the id if document didn't already have one
* @return
*/
public io.vertx.rxjava.ext.mongo.MongoClient insert(String collection, JsonObject document, Handler<AsyncResult<String>> resultHandler) {
delegate.insert(collection, document, resultHandler);
return this;
}
代码示例来源:origin: vert-x3/vertx-rx
/**
* Insert a document in the specified collection
* <p>
* This operation might change <i>_id</i> field of <i>document</i> parameter
* @param collection the collection
* @param document the document
* @param resultHandler result handler will be provided with the id if document didn't already have one
* @return
*/
public io.vertx.rxjava.ext.mongo.MongoClient insert(String collection, JsonObject document, Handler<AsyncResult<String>> resultHandler) {
delegate.insert(collection, document, resultHandler);
return this;
}
代码示例来源:origin: cescoffier/vertx-workshop
private void populateDatabase(Collection<Place> places) {
MongoClient mongo = MongoClient.createShared(vertx,
new JsonObject().put("db_name", "places").put("connection_string", mongoURL),
"places");
places.stream().forEach(place ->
mongo.insert("places", place.toJson(), result -> {
if (result.failed()) {
System.err.println("I was not able to insert '" + place.getName() + "' : " + result.cause().getMessage());
} else {
System.out.println("Place '" + place.getName() + "' inserted");
}
}));
}
代码示例来源:origin: silentbalanceyh/vertx-zero
static Future<JsonObject> insert(final String collection, final JsonObject data) {
return Ux.thenGeneric(future -> CLIENT.insert(collection, data, res -> {
if (res.succeeded()) {
LOGGER.debug(Info.MONGO_INSERT, collection, data);
future.complete(data);
} else {
LOGGER.debug(Info.MONGO_INSERT, collection, null);
future.complete();
}
}));
}
代码示例来源:origin: cn.vertxup/vertx-up
static Future<JsonObject> insert(final String collection, final JsonObject data) {
return Ux.thenGeneric(future -> CLIENT.insert(collection, data, res -> {
if (res.succeeded()) {
LOGGER.debug(Info.MONGO_INSERT, collection, data);
future.complete(data);
} else {
LOGGER.debug(Info.MONGO_INSERT, collection, null);
future.complete();
}
}));
}
代码示例来源:origin: io.vertx/vertx-lang-groovy
public static io.vertx.ext.mongo.MongoClient insert(io.vertx.ext.mongo.MongoClient j_receiver, java.lang.String collection, java.util.Map<String, Object> document, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>> resultHandler) {
io.vertx.core.impl.ConversionHelper.fromObject(j_receiver.insert(collection,
document != null ? io.vertx.core.impl.ConversionHelper.toJsonObject(document) : null,
resultHandler != null ? new io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>>() {
public void handle(io.vertx.core.AsyncResult<java.lang.String> ar) {
resultHandler.handle(ar.map(event -> event));
}
} : null));
return j_receiver;
}
public static io.vertx.ext.mongo.MongoClient insertWithOptions(io.vertx.ext.mongo.MongoClient j_receiver, java.lang.String collection, java.util.Map<String, Object> document, io.vertx.ext.mongo.WriteOption writeOption, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>> resultHandler) {
代码示例来源:origin: de.braintags/vertx-key-generator
private void initCounterCollection(Handler<AsyncResult<Void>> handler) {
LOGGER.info("Init of sequence collection with " + collectionName);
mongoClient.count(collectionName, referenceQuery, result -> {
if (result.failed()) {
handler.handle(Future.failedFuture(result.cause()));
} else {
long count = result.result();
if (count == 0) {
LOGGER.info("Inserting initial sequence record into collection " + collectionName);
this.mongoClient.insert(collectionName, referenceQuery, insertResult -> {
if (result.failed()) {
handler.handle(Future.failedFuture(insertResult.cause()));
} else {
LOGGER.info(result);
handler.handle(Future.succeededFuture());
}
});
} else {
LOGGER.info("Record exists already");
handler.handle(Future.succeededFuture());
}
}
});
}
代码示例来源:origin: cescoffier/my-vertx-first-app
if (count.result() == 0) {
mongo.insert(COLLECTION, bowmore.toJson(), ar -> {
if (ar.failed()) {
fut.fail(ar.cause());
} else {
mongo.insert(COLLECTION, talisker.toJson(), ar2 -> {
if (ar2.failed()) {
fut.failed();
代码示例来源:origin: folio-org/okapi
public void insert(T md, String id, Handler<ExtendedAsyncResult<Void>> fut) {
String s = Json.encodePrettily(md);
JsonObject document = new JsonObject(s);
encode(document, id);
cli.insert(collection, document, res -> {
if (res.succeeded()) {
fut.handle(new Success<>());
} else {
logger.warn("MongoUtil.insert " + id + " failed : " + res.cause());
logger.warn("Document: " + document.encodePrettily());
fut.handle(new Failure<>(INTERNAL, res.cause()));
}
});
}
代码示例来源:origin: cescoffier/my-vertx-first-app
private void addOne(RoutingContext routingContext) {
final Whisky whisky = Json.decodeValue(routingContext.getBodyAsString(),
Whisky.class);
mongo.insert(COLLECTION, whisky.toJson(), r ->
routingContext.response()
.setStatusCode(201)
.putHeader("content-type", "application/json; charset=utf-8")
.end(Json.encodePrettily(whisky.setId(r.result()))));
}
内容来源于网络,如有侵权,请联系作者删除!