MongoDB.live, free & fully virtual. Register Now MongoDB.live, free & fully virtual. Register Now

RealmSwift - Unable to get data after creating new collections

Hi there!

I’m using Realm Sync to develop an iOS app.
I recently added a new database with some collections and since I’m unable to retrieve any objects of any databases.
I tried to erase the new database and collections I added but still not working.
I also tried to restart Sync.

According to the log of my app, the connection is correctly established, the realm is well opened but it appears that there is no object on my collections. Here is a example where I’m opening a Realm to access a collection Customers to retrieve objects with the partition value “customers”:

2020-11-11 10:54:45.462465+0100 AppQuote[70213:555903] Sync: Realm sync client ([realm-core-10.1.1], [realm-sync-10.1.1])
    2020-11-11 10:54:45.462720+0100 AppQuote[70213:555903] Sync: Supported protocol versions: 1-1
    2020-11-11 10:54:45.462978+0100 AppQuote[70213:555903] Sync: Platform: iOS Darwin 19.6.0 Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64
    2020-11-11 10:54:45.463215+0100 AppQuote[70213:555903] Sync: Build mode: Release
    2020-11-11 10:54:45.463446+0100 AppQuote[70213:555903] Sync: Config param: max_open_files = 256
    2020-11-11 10:54:45.463682+0100 AppQuote[70213:555903] Sync: Config param: one_connection_per_session = 1
    2020-11-11 10:54:45.463928+0100 AppQuote[70213:555903] Sync: Config param: connect_timeout = 120000 ms
    2020-11-11 10:54:45.464324+0100 AppQuote[70213:555903] Sync: Config param: connection_linger_time = 30000 ms
    2020-11-11 10:54:45.464869+0100 AppQuote[70213:555903] Sync: Config param: ping_keepalive_period = 60000 ms
    2020-11-11 10:54:45.465275+0100 AppQuote[70213:555903] Sync: Config param: pong_keepalive_timeout = 120000 ms
    2020-11-11 10:54:45.465750+0100 AppQuote[70213:555903] Sync: Config param: fast_reconnect_limit = 60000 ms
    2020-11-11 10:54:45.466175+0100 AppQuote[70213:555903] Sync: Config param: disable_upload_compaction = 0
    2020-11-11 10:54:45.466601+0100 AppQuote[70213:555903] Sync: Config param: tcp_no_delay = 0
    2020-11-11 10:54:45.467075+0100 AppQuote[70213:555903] Sync: Config param: disable_sync_to_disk = 0
    2020-11-11 10:54:45.470877+0100 AppQuote[70213:555903] Sync: User agent string: 'RealmSync/10.1.1 (iOS Darwin 19.6.0 Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64) RealmObjectiveC/10.1.2 appquote-vyxhe'
    2020-11-11 10:54:45.473365+0100 AppQuote[70213:556552] Sync: Connection[1]: WebSocket::Websocket()
    2020-11-11 10:54:45.473870+0100 AppQuote[70213:556552] Sync: Connection[1]: Session[1]: Binding '/Users/xxxxx/Library/Developer/CoreSimulator/Devices/2ADD59A5-C62D-4DD0-8F75-17993EC0C380/data/Containers/Data/Application/F06C7170-7430-4A8C-8D6B-A86FC14E08DE/Documents/mongodb-realm/appquote-vyxhe/5ee8c66c6429e7d1c7cac98b/5ee8c66c6429e7d1c7cac98b%2F%2522customers%2522.realm' to '"customers"'
    2020-11-11 10:54:45.474406+0100 AppQuote[70213:556552] Sync: Connection[1]: Session[1]: Activating
    2020-11-11 10:54:45.475073+0100 AppQuote[70213:556552] Sync: Connection[1]: Session[1]: client_reset_config = false, Realm exists = true, async open = false, client reset = false
    2020-11-11 10:54:45.475877+0100 AppQuote[70213:556552] Sync: Opening Realm file: /Users/xxxxx/Library/Developer/CoreSimulator/Devices/2ADD59A5-C62D-4DD0-8F75-17993EC0C380/data/Containers/Data/Application/F06C7170-7430-4A8C-8D6B-A86FC14E08DE/Documents/mongodb-realm/appquote-vyxhe/5ee8c66c6429e7d1c7cac98b/5ee8c66c6429e7d1c7cac98b%2F%2522customers%2522.realm
    2020-11-11 10:54:45.477736+0100 AppQuote[70213:556552] Sync: Connection[1]: Session[1]: client_file_ident = 8, client_file_ident_salt = 7178767744394399870
    2020-11-11 10:54:45.478968+0100 AppQuote[70213:556552] Sync: Connection[1]: Session[1]: Progress handler called, downloaded = 961, downloadable(total) = 961, uploaded = 904, uploadable = 904, reliable_download_progress = 0, snapshot version = 5
    2020-11-11 10:54:45.479489+0100 AppQuote[70213:556552] Sync: Connection[1]: Resolving 'ws.realm.mongodb.com:443'
    2020-11-11 10:54:45.483831+0100 AppQuote[70213:556552] Sync: Connection[1]: Connecting to endpoint '52.49.130.120:443' (1/1)
    2020-11-11 10:54:45.512983+0100 AppQuote[70213:556552] Sync: Connection[1]: Connected to endpoint '52.49.130.120:443' (from '192.168.0.11:52757')
    2020-11-11 10:54:45.547766+0100 AppQuote[70213:555903] [CustomerTableViewController] Following changes occured on items:
    initial(Results<Customers> <0x618000049880> (

    ))
    2020-11-11 10:54:45.658334+0100 AppQuote[70213:556552] Sync: Connection[1]: WebSocket::initiate_client_handshake()
    2020-11-11 10:54:46.161267+0100 AppQuote[70213:556552] Sync: Connection[1]: WebSocket::handle_http_response_received()
    2020-11-11 10:54:46.161787+0100 AppQuote[70213:556552] Sync: Connection[1]: Negotiated protocol version: 1
    2020-11-11 10:54:46.162345+0100 AppQuote[70213:556552] Sync: Connection[1]: Will emit a ping in 41198 milliseconds
    2020-11-11 10:54:46.163012+0100 AppQuote[70213:556552] Sync: Connection[1]: Session[1]: Sending: BIND(path='"customers"', signed_user_token_size=469, need_client_file_ident=0, is_subserver=0)
    2020-11-11 10:54:46.163615+0100 AppQuote[70213:556552] Sync: Connection[1]: Session[1]: Sending: IDENT(client_file_ident=8, client_file_ident_salt=7178767744394399870, scan_server_version=7, scan_client_version=2, latest_server_version=7, latest_server_version_salt=6097420258415283507)
    2020-11-11 10:54:46.164094+0100 AppQuote[70213:556552] Sync: Connection[1]: Session[1]: Sending: MARK(request_ident=1)
    2020-11-11 10:54:46.980175+0100 AppQuote[70213:556552] Sync: Connection[1]: Session[1]: Received: MARK(request_ident=1)
    2020-11-11 10:54:46.980696+0100 AppQuote[70213:556552] Sync: Connection[1]: Session[1]: Sending: UPLOAD(progress_client_version=5, progress_server_version=7, locked_server_version=7, num_changesets=0)

Hi @Julien_Chouvet,
Could you please share the model of Customers object?

Hi @Pavel_Yakimenko

Here it is :

{
  "title": "Customers",
  "bsonType": "object",
  "required": [
    "_id",
    "_parentId"
  ],
  "properties": {
    "_id": {
      "bsonType": "objectId"
    },
    "_parentId": {
      "bsonType": "string"
    },
    "lastName": {
      "bsonType": "string"
    },
    "firstName": {
      "bsonType": "string"
    },
    "phoneNumber": {
      "bsonType": "string"
    },
    "email": {
      "bsonType": "string"
    },
    "address": {
      "bsonType": "string"
    },
    "notes": {
      "bsonType": "string"
    }
  }
}

Can we see the Swift Object model? Did you check the error log in the Realm Console? Any errors?

Are you using Developer mode?

The fact is that before I tried to add another db and other collections everything was working fine and I was able to get my customers objects as well as all the other objects of all my other collections. So I don’t think it come from my swift code.

class Customers: Object {

@objc dynamic var _id: ObjectId = ObjectId.generate()

@objc dynamic var _parentId: String = “”

@objc dynamic var address: String? = nil

@objc dynamic var email: String? = nil

@objc dynamic var firstName: String? = nil

@objc dynamic var invoices: String? = nil

@objc dynamic var lastName: String? = nil

@objc dynamic var notes: String? = nil

@objc dynamic var phoneNumber: String? = nil

@objc dynamic var quotes: String? = nil

override static func primaryKey() -> String? {

return “_id”

}

}

I checked the Realm console and there is no error. And I’m not using the developer mode.

I tried to create a new Realm app (within the same cluster) and it is working, I’m able to get my customers objects.
Any ideas why it is not working in the initial Realm app?

Maybe … sounds a little like my problem … if you’re making schema changes check they are reflected correctly in the Realm App… i think mine got out of whack and yet i couldn’t always find anything in the logs.

Yes I saw your post! Is it working now for you?
What do you mean by :

How can I check that?

I’ve just tried again with my first Realm app (i.e. initial configuration) and now it’s working again…

In Data Access / Schema … glad you’re up and running again .

1 Like