简体   繁体   English

Spring-data-couchbase-运行更新查询

[英]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.

相关问题 spring-data-couchbase中的@Query与Pageable参数 - @Query with Pageable parameter in spring-data-couchbase Spring-Data-Couchbase-运行非临时参数化查询 - Spring-data-couchbase - running non ad-hoc parametrized query 在spring-data-couchbase(N1QL)中计数查询 - Counting query in spring-data-couchbase (N1QL) 使用 spring-data-couchbase 查询 couchbase,使用多列 - querying couchbase with spring-data-couchbase, using multiple columns 如何使用带有@Query 的 spring-data-couchbase 从文档中返回 boolean - How to return a boolean from a document using spring-data-couchbase with @Query 我正在使用spring-data-couchbase,但是从方法名称创建查询不起作用 - I am using spring-data-couchbase , but the Query creation from method names does not work spring-data-couchbase对不存在的文档抛出DocumentDoesNotExistException - spring-data-couchbase throws DocumentDoesNotExistException for non-existent documents 使用PageRequest查找所有文档时出现spring-data-couchbase错误 - spring-data-couchbase error while finding all documents with PageRequest 如何使用 spring-data-couchbase 为特定的 Couchbase 文档设置 TTL? - How to set TTL for a specific Couchbase document using spring-data-couchbase? spring-data-couchbase - org.springframework.data.mapping.model.MappingException - spring-data-couchbase - org.springframework.data.mapping.model.MappingException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM