Skip to content

Delete N1QL query is deleting all documents instead of deleting only documents that matches the criteria #1131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cheth83 opened this issue Apr 23, 2021 · 3 comments · Fixed by #1135
Labels
type: bug A general bug

Comments

@cheth83
Copy link

cheth83 commented Apr 23, 2021

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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 23, 2021
@thenoslav
Copy link

Hello, i had similar isssue. My query was:

@Query("#{#n1ql.delete} WHERE role IN $1 AND group = $2 AND `type` = \"#{T(com.something.service.persistance.entities.Rule).TYPE_DATABASE_LABEL}\" #{#n1ql.returning}")
List<Rule> deleteRulesByRoleAndGroup(JsonArray roles, String group);

This query has deleted all my documents in bucket (predicates was ignored).
I found out that when method name is starting with "delete", then it has been using ReactiveRemoveByQueryOperationSupport.assembleDeleteQuery() method for assembling query.
My query before this calling:
image

and assembleDeleteQuery is returning:
image

image

@mikereiche
Copy link
Collaborator

I'm investigating this.

@mikereiche mikereiche added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels May 3, 2021
@mikereiche
Copy link
Collaborator

override for toN1qlRemoveString() in StringQuery was missing.

mikereiche added a commit that referenced this issue May 3, 2021
mikereiche added a commit that referenced this issue May 4, 2021
mikereiche added a commit that referenced this issue May 4, 2021
Closes #1131.
Original pull request: #1135.

Co-authored-by: mikereiche <[email protected]>
mikereiche added a commit that referenced this issue Aug 9, 2021
Closes #1131.
Original pull request: #1135.

Co-authored-by: mikereiche <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants