问题
I am working on spring and couchbase and now want to upload data to couchbase with the help of my spring API but got to know that spring does not support N1QL, So is there any other way to achieve that or a shEL query
insert into bucket1(key,value)
values("Aman--12/04/1995",
{
"English":[{ "midterm": 34, "endterm": 67 }],
"Maths":[{ "midterm": 20, "endterm": 40 }],
"Computer":[{ "midterm": 48, "endterm": 90 }]
})
UPDATE bucketName USE KEYS id
SET arrayname = ARRAY_PUT(IFNULL(Arrayname[]),{"Sports": "89"})
回答1:
If you can't do something via spEL you can always use pure n1ql for it:
@Override
public void updateAreaName(String areaName, String areaId) {
String queryString = "UPDATE "+getBucketName()+" set areaName = '"+areaName+"' WHERE "+getClassFilter()+" " +
" and areaId = '"+areaId+"' RETURNING meta().id";
N1qlParams params = N1qlParams.build().consistency(ScanConsistency.REQUEST_PLUS).adhoc(true);
ParameterizedN1qlQuery query = N1qlQuery.parameterized(queryString, JsonObject.create(), params);
resourceRepository.getCouchbaseOperations().getCouchbaseBucket().query(query);
}
private String getBucketName() {
return resourceRepository.getCouchbaseOperations().getCouchbaseBucket().bucketManager().info().name();
}
private String getClassFilter(){
return "_class = '" + QResource.class.getName() + "' ";
}
来源:https://stackoverflow.com/questions/55095570/can-we-convert-n1ql-to-shel-query-for-spring-use