luky luky - 1 year ago 98
Java Question

realm java - bulk update on RealmResults or RealmQuery

In Realm ObjC it is possible to perform update operation on RLMResults collection like this:

RLMResults<Pubs *> *pubsToDelete = [Pubs objectsWhere: @"NOT (pubId IN %@)", apiIds];

[[RLMRealm defaultRealm] transactionWithBlock:^{
// all pubs in pubsToDelete will be updated
[pubsToDelete setValue:@YES forKeyPath:@"deleted"];

Is it possible also in Java version or I have to perform iteration over RealmResults and set the value for each object? Like

RealmResults<Pubs> results = query.findAll();

for (Pubs p : results) {
p.deleted = 1;

Answer Source

Yes, in Realm-Java you need to iterate for all objects.

realm.executeTransaction(new Realm.Transaction() {
    public void execute(Realm realm) {
        RealmResults<Pubs> results = query.findAll();
        for(Pub p : results) {
            p.deleted = 1;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download