Hello!
I am trying to fetch list of document ids from indexed collection by indexed fields. For now I’ve managed to do this in following way:
List < EntityId> findAllByXYZ(String XYZ);
record EntityId(String id) {}
but that probably is fetching whole document id and then only later filtering just the document id’s. Also this seems rather slow comparing to query on capella returning just the ids.
Is there any way to write spring data n1ql query to return just the id lists based on some field?
I tried to also do it in following way:
@Query(
“SELECT documentId from #{n1ql.bucket}.#{n1ql.scope}.#{n1ql.collection}”
+ " where #{n1ql.filter}"
+ " and xyz = $xyz")
List < String> findIdsByXyz(String xyz);
but it throws following error:
EL1008E: Property or field ‘n1ql’ cannot be found on object of type ‘java.lang.Object’ - maybe not public or not valid?
SELECT RAW META().id
this saves 7 bytes each entry ({“id”:}) returns array of strings vs array of objects (RAW can be used only when single projection field)
RAW won’t work in this case as spring-data-couchbase repository methods always expect each row to be json.
The java SDK can be called directly as follows, but there is no #n1ql variable substitution.
myRepository.getOperations().getCouchbaseClientFactory().getCluster() .query("SELECT RAW META().id from mybucket.myscope.mycollection where type='<classname>' and xyz = $xyz", QueryOptions.queryOptions().parameters(JsonObject.create().put("xyz", "someValue")));