Description
I have a simple requirement to delete all documents whose date is less than specified in the query. but whatever option I try, it’s deleting all documents from db. Code is written in Java Spring Boot project.
versions:
Sprinboot-2.4.4.
spring data couchbase-4.1.6
couchbase server: 6
Sample codes I tried: I tried passing date argument as String, LocalDateTime, etc but none of it worked.
@Query("#{#n1ql.delete} WHERE #{#n1ql.filter} AND dateParam < MILLIS($1)")
void selectDateTime(LocalDateTime/String dateParam);
@Query("#{#n1ql.delete} WHERE #{#n1ql.filter} AND dateParam < $1")
void selectDateTime(String dateParam);
@Query("#{#n1ql.delete} WHERE #{#n1ql.filter} AND dateParam < MILLIS($1) #{#n1ql.returning}")
List selectDateTime(String dateParam);
dateParam passed as String was: “2021-04-07T06:47:32Z”
I also tried passing LocalDateTime- LocalDateTime.of(2021, 4, 7, 06, 47, 32);
To confirm there is nothing wrong in the criteria or data type or values I'm passing to above queries, I tried select query with same where clause and it's working perfectly fine - correct number of documents matching criteria is returned.
@Query("#{#n1ql.selectEntity} WHERE #{#n1ql.filter} AND syncTimeStamp < MILLIS($1)")
void selectDateTime(LocalDateTime/String date);
It’s surprising it’s working for select query but not for delete query.
If I run query from couchbase UI, it works fine - only documents that matches condition gets deleted.
delete from DB_NAME where dateParam < 1618188052352
Any help would be appreciated.