Skip to content
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

(Reactive)CouchbaseTemplate - removeByQuery always remove all data [DATACOUCH-615] #917

Closed
spring-projects-issues opened this issue Sep 21, 2020 · 1 comment
Assignees

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Sep 21, 2020

haal opened DATACOUCH-615 and commented

Using CouchbaseTemplate to remove data by specified query

couchbaseTemplate.removeByQuery(Some.class).matching(query).all();

will always remove all data and ignore query sent in matching part. Same is true for ReactiveCouchbaseTemplate.
Tested with v4.0.4 using Java 11.
 

Example of JUnit test (in class CouchbaseTemplateQueryIntegrationTests):

@Test
void removeByQueryMatching() {
   User user1 = new User(UUID.randomUUID().toString(), "user1", "user1");
   User user2 = new User(UUID.randomUUID().toString(), "user2", "user2");
   User specialUser = new User(UUID.randomUUID().toString(), "special", "special");

   couchbaseTemplate.upsertById(User.class).all(Arrays.asList(user1, user2, specialUser));

   assertTrue(couchbaseTemplate.existsById().one(user1.getId()));
   assertTrue(couchbaseTemplate.existsById().one(user2.getId()));
   assertTrue(couchbaseTemplate.existsById().one(specialUser.getId()));

   Query nonSpecialUsers = new Query(QueryCriteria.where("firstname").notLike("special"));

   couchbaseTemplate.removeByQuery(User.class).consistentWith(QueryScanConsistency.REQUEST_PLUS)
         .matching(nonSpecialUsers)
         .all();

   assertNull(couchbaseTemplate.findById(User.class).one(user1.getId()));
   assertNull(couchbaseTemplate.findById(User.class).one(user2.getId()));
   assertNotNull(couchbaseTemplate.findById(User.class).one(specialUser.getId())); //this assert because all data is deleted

} 

Affects: 4.0.4 (Neumann SR4)

Referenced from: pull request #264

Backported to: 4.0.5 (Neumann SR5)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.