本文整理汇总了Java中io.vertx.ext.mongo.MongoClient.save方法的典型用法代码示例。如果您正苦于以下问题:Java MongoClient.save方法的具体用法?Java MongoClient.save怎么用?Java MongoClient.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.ext.mongo.MongoClient
的用法示例。
在下文中一共展示了MongoClient.save方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: example13_0
import io.vertx.ext.mongo.MongoClient; //导入方法依赖的package包/类
public void example13_0(MongoClient mongoService) {
JsonObject document = new JsonObject()
.put("title", "The Hobbit")
//ISO-8601 date
.put("publicationDate", new JsonObject().put("$date", "1937-09-21T00:00:00+00:00"));
mongoService.save("publishedBooks", document, res -> {
if (res.succeeded()) {
String id = res.result();
mongoService.findOne("publishedBooks", new JsonObject().put("_id", id), null, res2 -> {
if (res2.succeeded()) {
System.out.println("To retrieve ISO-8601 date : "
+ res2.result().getJsonObject("publicationDate").getString("$date"));
} else {
res2.cause().printStackTrace();
}
});
} else {
res.cause().printStackTrace();
}
});
}
示例2: example14_01_dl
import io.vertx.ext.mongo.MongoClient; //导入方法依赖的package包/类
@Source(translate = false)
public void example14_01_dl(MongoClient mongoService) {
//This could be a serialized object or the contents of a pdf file, etc, in real life
byte[] binaryObject = new byte[40];
JsonObject document = new JsonObject()
.put("name", "Alan Turing")
.put("binaryStuff", new JsonObject().put("$binary", binaryObject));
mongoService.save("smartPeople", document, res -> {
if (res.succeeded()) {
String id = res.result();
mongoService.findOne("smartPeople", new JsonObject().put("_id", id), null, res2 -> {
if (res2.succeeded()) {
byte[] reconstitutedBinaryObject = res2.result().getJsonObject("binaryStuff").getBinary("$binary");
//This could now be de-serialized into an object in real life
} else {
res2.cause().printStackTrace();
}
});
} else {
res.cause().printStackTrace();
}
});
}
示例3: example14_02_dl
import io.vertx.ext.mongo.MongoClient; //导入方法依赖的package包/类
public void example14_02_dl(MongoClient mongoService) {
//This could be a the byte contents of a pdf file, etc converted to base 64
String base64EncodedString = "a2FpbHVhIGlzIHRoZSAjMSBiZWFjaCBpbiB0aGUgd29ybGQ=";
JsonObject document = new JsonObject()
.put("name", "Alan Turing")
.put("binaryStuff", new JsonObject().put("$binary", base64EncodedString));
mongoService.save("smartPeople", document, res -> {
if (res.succeeded()) {
String id = res.result();
mongoService.findOne("smartPeople", new JsonObject().put("_id", id), null, res2 -> {
if (res2.succeeded()) {
String reconstitutedBase64EncodedString = res2.result().getJsonObject("binaryStuff").getString("$binary");
//This could now converted back to bytes from the base 64 string
} else {
res2.cause().printStackTrace();
}
});
} else {
res.cause().printStackTrace();
}
});
}
示例4: example15_dl
import io.vertx.ext.mongo.MongoClient; //导入方法依赖的package包/类
public void example15_dl(MongoClient mongoService) {
String individualId = new ObjectId().toHexString();
JsonObject document = new JsonObject()
.put("name", "Stephen Hawking")
.put("individualId", new JsonObject().put("$oid", individualId));
mongoService.save("smartPeople", document, res -> {
if (res.succeeded()) {
String id = res.result();
JsonObject query = new JsonObject().put("_id", id);
mongoService.findOne("smartPeople", query, null, res2 -> {
if (res2.succeeded()) {
String reconstitutedIndividualId = res2.result()
.getJsonObject("individualId").getString("$oid");
} else {
res2.cause().printStackTrace();
}
});
} else {
res.cause().printStackTrace();
}
});
}
示例5: example1
import io.vertx.ext.mongo.MongoClient; //导入方法依赖的package包/类
public void example1(MongoClient mongoClient) {
// Document has no id
JsonObject document = new JsonObject()
.put("title", "The Hobbit");
mongoClient.save("books", document, res -> {
if (res.succeeded()) {
String id = res.result();
System.out.println("Saved book with id " + id);
} else {
res.cause().printStackTrace();
}
});
}
示例6: example2
import io.vertx.ext.mongo.MongoClient; //导入方法依赖的package包/类
public void example2(MongoClient mongoClient) {
// Document has an id already
JsonObject document = new JsonObject()
.put("title", "The Hobbit")
.put("_id", "123244");
mongoClient.save("books", document, res -> {
if (res.succeeded()) {
// ...
} else {
res.cause().printStackTrace();
}
});
}
示例7: example16
import io.vertx.ext.mongo.MongoClient; //导入方法依赖的package包/类
public void example16(MongoClient mongoClient) {
JsonObject document = new JsonObject()
.put("title", "The Hobbit");
mongoClient.save("books", document, res -> {
if (res.succeeded()) {
mongoClient.distinct("books", "title", String.class.getName(), res2 -> {
System.out.println("Title is : " + res2.result().getJsonArray(0));
});
} else {
res.cause().printStackTrace();
}
});
}
示例8: example16_d1
import io.vertx.ext.mongo.MongoClient; //导入方法依赖的package包/类
public void example16_d1(MongoClient mongoClient) {
JsonObject document = new JsonObject()
.put("title", "The Hobbit");
mongoClient.save("books", document, res -> {
if (res.succeeded()) {
mongoClient.distinctBatch("books", "title", String.class.getName())
.handler(book -> System.out.println("Title is : " + book.getString("title")));
} else {
res.cause().printStackTrace();
}
});
}
示例9: example17
import io.vertx.ext.mongo.MongoClient; //导入方法依赖的package包/类
public void example17(MongoClient mongoClient) {
JsonObject document = new JsonObject()
.put("title", "The Hobbit")
.put("publicationDate", new JsonObject().put("$date", "1937-09-21T00:00:00+00:00"));
JsonObject query = new JsonObject()
.put("publicationDate",
new JsonObject().put("$gte", new JsonObject().put("$date", "1937-09-21T00:00:00+00:00")));
mongoClient.save("books", document, res -> {
if (res.succeeded()) {
mongoClient.distinctWithQuery("books", "title", String.class.getName(), query, res2 -> {
System.out.println("Title is : " + res2.result().getJsonArray(0));
});
}
});
}
示例10: example17_d1
import io.vertx.ext.mongo.MongoClient; //导入方法依赖的package包/类
public void example17_d1(MongoClient mongoClient) {
JsonObject document = new JsonObject()
.put("title", "The Hobbit")
.put("publicationDate", new JsonObject().put("$date", "1937-09-21T00:00:00+00:00"));
JsonObject query = new JsonObject()
.put("publicationDate", new JsonObject()
.put("$gte", new JsonObject().put("$date", "1937-09-21T00:00:00+00:00")));
mongoClient.save("books", document, res -> {
if (res.succeeded()) {
mongoClient.distinctBatchWithQuery("books", "title", String.class.getName(), query)
.handler(book -> System.out.println("Title is : " + book.getString("title")));
}
});
}