使用Spring Data突变Couchbase Sub文档

时间:2017-09-05 12:58:06

标签: spring spring-data couchbase

尝试通过Spring数据在Couchbase中附加值来改变子文档。但它失败了:

//示例文档

{ "type": "account", "events": [ { "transactionReference": "", "value": 100 } ] }

目标是在事件数组中再添加一个条目。以下是正在执行操作的片段。

Event eventObj = new Event(...); repository.getCouchbaseOperations().getCouchbaseBucket() .mutateIn("doc_id") .arrayPrepend("events", eventObj,false).execute();

更新 之前缺少execute()方法。 下面是异常的堆栈跟踪

com.couchbase.client.core.CouchbaseException: FAILURE at com.couchbase.client.java.subdoc.SubdocHelper.commonSubdocErrors(SubdocHelper.java:95) at com.couchbase.client.java.subdoc.AsyncMutateInBuilder$12.call(AsyncMutateInBuilder.java:923) at com.couchbase.client.java.subdoc.AsyncMutateInBuilder$12.call(AsyncMutateInBuilder.java:917) at com.couchbase.client.java.subdoc.AsyncMutateInBuilder$17.call(AsyncMutateInBuilder.java:1010) at com.couchbase.client.java.subdoc.AsyncMutateInBuilder$17.call(AsyncMutateInBuilder.java:1000) at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:69) at rx.observers.Subscribers$5.onNext(Subscribers.java:235) at rx.internal.operators.OnSubscribeDoOnEach$DoOnEachSubscriber.onNext(OnSubscribeDoOnEach.java:101) at rx.internal.producers.SingleProducer.request(SingleProducer.java:65) at rx.Subscriber.setProducer(Subscriber.java:209) at rx.Subscriber.setProducer(Subscriber.java:205) at rx.internal.operators.OnSubscribeMap$MapSubscriber.setProducer(OnSubscribeMap.java:102) at rx.Subscriber.setProducer(Subscriber.java:205) at rx.Subscriber.setProducer(Subscriber.java:205) at rx.subjects.AsyncSubject.onCompleted(AsyncSubject.java:106) at com.couchbase.client.core.endpoint.AbstractGenericHandler.completeResponse(AbstractGenericHandler.java:375) at com.couchbase.client.core.endpoint.AbstractGenericHandler.access$000(AbstractGenericHandler.java:69) at com.couchbase.client.core.endpoint.AbstractGenericHandler$1.call(AbstractGenericHandler.java:393) at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: rx.exceptions.OnErrorThrowable$OnNextValue: OnError while emitting onNext value: com.couchbase.client.core.message.kv.subdoc.simple.SimpleSubdocResponse.class

1 个答案:

答案 0 :(得分:0)

Couchbase Sub-Document API是一个构建器API,允许您将多个mutate命令(或多个检索命令)链接在一起。使用Java SDK,您必须调用execute()来执行这些突变。

Event eventObj = new Event(...);
repository.getCouchbaseOperations().getCouchbaseBucket()
        .mutateIn("doc_id")
        .arrayPrepend("events", eventObj,false)
        .execute();