[英]Spring-data-couchbase - running update query
Is any possibility to execute N1QL update query using spring-data? 是否有可能使用spring-data执行N1QL更新查询?
Ie I have following update query: 即我有以下更新查询:
"UPDATE USERS USE KEYS $id SET location = $location"
I tried to use couchbaseTemplate.queryN1QL
method, but it doesn't work. 我尝试使用
couchbaseTemplate.queryN1QL
方法,但是它不起作用。
Is there any solution of this problem using spring data or even native couchbase java SDK? 使用spring数据甚至本机ouchbase Java SDK可以解决此问题吗?
the CouchbaseTemplate
is more tailored towards Spring Data document's use case, so it expects to run queries that return specific elements and will end up unmarshalled into entities (eg. a User
object). CouchbaseTemplate
更适合于Spring Data文档的用例,因此它希望运行返回特定元素的查询,并最终将它们编组为实体(例如, User
对象)。
if you want to run a more freeform query, like your update, you can always access the native SDK from the template. 如果您想运行更自由形式的查询(例如更新),则始终可以从模板访问本机SDK。 In your case:
在您的情况下:
String paStatement = "UPDATE USERS USE KEYS $id SET location = $location";
JsonObject paramValues = JsonObject.create().put("id", theId).put("location", "theLocation");
N1qlQuery query = N1qlQuery.parametrized(paStatement, paramValues);
template.getCouchbaseBucket().query(query);
I think you can add RETURNING *
at the end of your UPDATE
statement. 我认为您可以在
UPDATE
语句的末尾添加RETURNING *
。 It would make the statement returns something. 它将使该语句返回某些内容。 It works for me.
这个对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.