Using Local NON sync Realm file

I’m integrating the MongoRealm into existing iOS App. In this App - I have a Local Writable Realm file with some objects that I don’t wish to participate in Realm Sync as this contains a lot of catalog data.

So I have a used a specific file name based Realm Configuration to initialise the Realm object.

var config = Realm.Configuration(schemaVersion: 83)
guard let fileUrl = config.fileURL else {
    throw AppError.invalidState("fileURL of realm config is nil")
}
config.fileURL = fileUrl.deletingLastPathComponent().appendingPathComponent("content.realm")
config.readOnly = false
let realm = try Realm(configuration: config)

With the above - I’m able to see the file created in the documents folder.
I’m also able to create a new object in that Realm using the following definition

class Grade: Object {
    @objc dynamic var id=""
    @objc dynamic var sno=0
    @objc dynamic var name=""
    @objc dynamic var version=0
    @objc dynamic var timestamp = Date()
    let linkedPrimarySkills = List<String>()
    override static func primaryKey() -> String? {
        return "id"
    }
    
    override static func indexedProperties() -> [String] {
        return ["sno", "name"]
    }
}

And when I query the above realm using the realm.objects(Grade.self) - It returns the object I wrote as expected.

But if I use the find by primary key method to pick a specific object -

let grade3 = realm.object(ofType: Grade.self, forPrimaryKey: "003")

it returns NIL.

Since the above class is NOT part of a Synced Realm - I don’t have a partition key. Also unlike the collections in Synced Realm - I’m using a simple primary key called id. All this code is from Classic Realm usage as a local data store.

So I’m puzzled how this basic functionality is broken ? Is it not possible to have a local (Non-sync) realm co-exist with a sync realm.

Thanks
Ram

While trying to further collect details on the above - I also did predicate queries

While let grade3 = realm.object(ofType: Grade.self, forPrimaryKey: "003") is returning NIL - I’m able to do use the filtered query let filtered = grades.filter(NSPredicate(format: "id == %@", "003")) to find the record .

So looks like a bug to me. It will be great if someone can help confirm?

Best regards
Ram

Have you committed the transaction before querying on the primary key? If I use createOrUpdateModified to add the object to Realm and then get all objects of that type before committing, I get one object. However, if I query for the object by its primary key, nil is returned.

Yes I’m not writing & immediately trying to read it. Write is committed. I’ve also closed the app & double checked by opening the Realm file in realm studio. Object is definitely there. But when I relaunch the app & query based on Primary key - its nil

@Ram_Sundaram This looks a correct to me, can you open an issue here with a repro case?

@Ian_Ward Yes I had done so yesterday even before I posted here.

https://github.com/realm/realm-cocoa/issues/6672 - sorry missed referring to that issue over here.

thanks
Ram