How to give dynamic field name from java using ReactiveCouchbaseRepository?

Hi Team,
Can we give the filed name dynamically from the java code to repository, please guide me.

My Query looks like below
String QUERY_BY_PARAMS = "#{#n1ql.selectEntity} WHERE #{#n1ql.filter} " +
"AND planningGroupEventId = $1 " +
"AND rangeProductChangeType in $2 " +
"#{#country == null ? ‘’ : 'AND country = $3 '} " +
"#{#queryKeyword == null ? ‘’ : 'AND $4 = true '} ";

@Query(QUERY_BY_PARAMS)
Mono<Long> countByParams(
        Integer planningGroupEventId,
        List<String> changeTypes,
        String country,
        String queryKeyword
);

Here queryKeyword is the filed name which is boolean, which we are trying to read through $4.

Thanks,
Kurien.

Use the SPEL token #{[n]} where n is the index of the parameter.

Actually this is more suited to using the template findByQuery(…).match(…).count()

1 Like

Thanks Mreiche, it worked,

but the column index stats from 0 and the value index starts from 1 :wink:

but the column index stats from 0 and the value index starts from 1

spring framework does that. The sql++/n1ql parameter index starts at 1 because that’s
what sql did.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.