Uploaded image for project: 'Realm Java SDK'
  1. Realm Java SDK
  2. RJAVA-1224

Facing deleting issue.

      How frequently does the bug occur?

      Always

      Description

      I have been facing an issue for quite some time now and have searched extensively for a solution, but to no avail. The problem I'm encountering is that Realm is unable to delete all objects, leaving some objects undeleted.

      In my application, there is a feature that involves downloading JSON documents from an API and storing this data offline using Realm.

      Problem and Issue:
      I store data based on files in MongoDB, and when file data is deleted from MongoDB, I have managed to ensure that the corresponding file data is deleted in Android as well. However, there are numerous files to be deleted, not just one. As a result, some file data remains undeleted despite attempts to use queries.

      For instance, if there are 5 files data to be deleted, 1 file's data remains undeleted while the others are successfully removed from the offline database.

      Please find the attached code below. This should provide you with an understanding of my implementation:

      `private void deleteDataFromRealm() {
      Observable.fromCallable(() -> {
      long totalRemainRecord = 0;
      try (Realm realm = Realm.getDefaultInstance()) {
      totalRemainRecord = realm.where(VehicleModel.class).in("fileName", deletedFiles.toArray(new String[]{})).count();
      if (totalDeleteRecord == 0)

      { totalDeleteRecord = totalRemainRecord; }

      deleteCount += batchSize;
      realm.executeTransaction(r -> r.where(VehicleModel.class)
      .limit(batchSize)
      .in("fileName", deletedFiles.toArray(new String[]{})).findAll().deleteAllFromRealm());

                          return totalRemainRecord;
                      } catch (Exception e) {
                          e.printStackTrace();
      
                          return totalRemainRecord;
                      }
                  }) // Specify the thread to perform work on
                  .subscribeOn(Schedulers.io())
                  .observeOn(AndroidSchedulers.mainThread()) // Specify the thread to receive results on (e.g., UI thread)
                  .subscribe(totalRemainRecord -> {
                      if (totalRemainRecord <= batchSize) {
                          viewModel.getIsManage().postValue(true);
                      } else {
                          setProgressBar(deleteCount, totalDeleteRecord);
                          deleteDataFromRealm();
                      }
                  }, error -> Log.d("OnSearchError", error.getMessage()));
      }`
      

      I am using relam 10.15.1
      Gradle version is 8.1.1

      Stacktrace & log output

      No response

      Can you reproduce the bug?

      No

      Reproduction Steps

      I'm encountering a peculiar situation where I'm unable to reproduce an issue in my local application environment. Strangely, this issue only arises in the production APK or the live version of the app. I've diligently maintained logs, which allowed me to detect this problem.

      Unfortunately, I don't have specific steps to replicate the issue as it appears to be specific to the production environment.

      Version

      10.15.1

      What Atlas App Services are you using?

      Local Database only

      Are you using encryption?

      No

      Platform OS and version(s)

      Android

      Build environment

      No response

            Assignee:
            Unassigned Unassigned
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: