Unable to fetch details on Querying realm via Android Sdk

RealmQuery query = realm
.where(User.class);

 query = query.beginGroup();

query = query.beginGroup().contains(“firstname”, firstName, Case.INSENSITIVE)
.or().contains(“lastname”, lastName, Case.INSENSITIVE).endGroup();
RealmResults userModels = query.findAllAsync();

mongodb realm - atlas db has data populated of users, for some reasons im not getting any results

Do you have the full code? It isn’t clear what you mean by “Not getting any results” and where it happens?

public void searchUsers(User userModel, String searchName, CompletionUsers completionUsers) {
try {
if((searchName.isEmpty() && searchFull.isEmpty() && school.isEmpty() && company.isEmpty() && currentCity.isEmpty() && hometown.isEmpty())) {
completionUsers.onSuccess(new User[0]);
return;
} // if
RealmQuery query = realm
.where(User.class);
if(!searchName.isEmpty()) {
String firstName = searchName;
String lastName = searchName;
query = query.beginGroup();
query = query.beginGroup().contains(“firstname”, firstName, Case.INSENSITIVE)
.or().contains(“lastname”, lastName, Case.INSENSITIVE).endGroup();

            query = query.endGroup();
        }
        query = query.and().notEqualTo("_id", userModel._id);
        RealmResults<User> userModels = query.findAllAsync();
        userModels.addChangeListener(new RealmChangeListener<RealmResults<User>>() {
            @Override
            public void onChange(RealmResults<User> users) {
                if(userModels.isLoaded()) {
                    Vector<User> vector = new Vector();
                    RealmResults<User> results = userModels.sort("firstname", Sort.ASCENDING, "lastname", Sort.ASCENDING);
                    for (int i = 0; i < results.size(); i++) {
                        vector.add(results.get(i));
                    } // for
                    User[] result = new User[vector.size()];
                    vector.copyInto(result);
                    completionUsers.onSuccess(result);
                    userModels.removeAllChangeListeners();
                } // if
            }
        });
    }
    catch (Exception e) {
        e.printStackTrace();
        completionUsers.onFail(e.getMessage());
    }
}

and im call this as
RealmHelper.shared.searchUsers(GlobalService.shared.getMe(), !isSimple ? “” : simpleText, new RealmHelper.CompletionUsers() {
@Override
public void onSuccess(HPUser[] userRealm) {

}

});
simpleText is my searchtext

This code here RealmResults<User> userModels = query.findAllAsync(); might be problematic as the RealmResult risk getting GC’ed before the callback triggers. You should move that to a class to ensure that doesn’t happen.

I suspect that is what you are seeing, as that would cause the changelistener to never trigger. Otherwise it looks correct

Can u explain more about this ?

the code is already in HelperClass

Something like this

class Activity {
  lateinit var results: RealmResults<Person>

 fun onStart() {
   results = realm.where<Person>().findAllAsync()
   results.addChangeListener(...)
 }

 fun onStop() {
    results.removeAllChangeListeners()
 }

}

Hi,
This is only giving the current user, other users are not getting filtered