本文整理汇总了Java中com.couchbase.client.java.Bucket.insert方法的典型用法代码示例。如果您正苦于以下问题:Java Bucket.insert方法的具体用法?Java Bucket.insert怎么用?Java Bucket.insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.couchbase.client.java.Bucket
的用法示例。
在下文中一共展示了Bucket.insert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testServer
import com.couchbase.client.java.Bucket; //导入方法依赖的package包/类
@Test
public static void testServer()
throws InterruptedException, IOException {
CouchbaseTestServer couchbaseTestServer = new CouchbaseTestServer(TestUtils.findFreePort());
couchbaseTestServer.start();
int port = couchbaseTestServer.getPort();
int serverPort = couchbaseTestServer.getServerPort();
try {
CouchbaseEnvironment cbEnv = DefaultCouchbaseEnvironment.builder().bootstrapHttpEnabled(true)
.bootstrapHttpDirectPort(port)
.bootstrapCarrierDirectPort(serverPort)
.connectTimeout(TimeUnit.SECONDS.toMillis(15))
.bootstrapCarrierEnabled(true).build();
CouchbaseCluster cbCluster = CouchbaseCluster.create(cbEnv, "localhost");
Bucket bucket = cbCluster.openBucket("default","");
try {
JsonObject content = JsonObject.empty().put("name", "Michael");
JsonDocument doc = JsonDocument.create("docId", content);
JsonDocument inserted = bucket.insert(doc);
}
catch (Exception e)
{
Assert.fail("Should not throw exception on insert", e);
}
}
finally
{
couchbaseTestServer.stop();
}
}
示例2: main
import com.couchbase.client.java.Bucket; //导入方法依赖的package包/类
public static void main(String[] args) {
Cluster cluster = CouchbaseCluster.create(DefaultCouchbaseEnvironment
.builder()
.queryEnabled(true)
.build());
Bucket defaultBucket = cluster.openBucket("default");
defaultBucket.remove("user:walter");
JsonArray friends = JsonArray.empty()
.add(JsonObject.empty().put("name", "Mike Ehrmantraut"))
.add(JsonObject.empty().put("name", "Jesse Pinkman"));
JsonObject content = JsonObject.empty()
.put("firstname", "Walter")
.put("lastname", "White")
.put("age", 52)
.put("aliases", JsonArray.from("Walt Jackson", "Mr. Mayhew", "David Lynn"))
.put("friends", friends);
JsonDocument walter = JsonDocument.create("user:walter", content);
JsonDocument inserted = defaultBucket.insert(walter);
JsonDocument foundGuy = defaultBucket.get("user:walter");
System.out.println(foundGuy.content().toMap());
Bucket beerBucket = cluster.openBucket("beer-sample");
N1qlQueryResult result = beerBucket.query(N1qlQuery.simple(select("*").from(i("beer-sample")).limit(10)));
System.out.println("Errors found: " + result.errors());
for (N1qlQueryRow row : result.allRows()) {
JsonObject jsonObject = row.value();
System.out.println(jsonObject.toMap());
}
cluster.disconnect();
}