question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

realm object is empty on first run of app

See original GitHub issue

I have an app that communicates with a read-only server hosted realm. I have tried this via a localhost server on my Mac (ROS v1.7.6) as well as an Amazon hosted Linux server (ROS v1.8.1). I have tried this with realm.js version 1.3.1 - 1.8.3.

If I choose Simulator->Reset Content and Settings from the iOS Simulator (to simulate a user who downloads the app for the first time), my console.log for the realm’s length equals 0 after calling this function. I can call this function multiple times and its always 0 after wipping out the storage. If I hit comand-r to reload the React Native app inside the simulator and then call this function it returns 1300+ (what is expected), and then works for all future runs of the app.

I also tested this same code on the Android simulator. It returns 0 at all times, no matter how many times I reload. I also tested this same code in a blank node.js project with nothing else loaded besides realm and it corectly returned 1300+ records. All “error” objcts are null or undefined and both “user” and “realm” objects look valid when console.logged.

What could be happening that would explain this behavior?

Realm.Sync.User.registerWithProvider(
            "http://localhost:9080",
            "custom/cgpsauth",
            accessToken,
            (error, user) => {
              console.log("error-- " + error);
              if (!error) {
                Realm.openAsync(
                  {
                    schema: [
                      StudentSchema,
                      ParentPhonesSchema,
                      ParentsSchema,
                      ParentAdressSchema,
                      DirectoryFavoritesSchema
                    ],
                    sync: {
                      user: user,
                      url: "realm://localhost:9080/cgps-app-v1"
                    }
                  },
                  (error, realm) => {
                    // Realm is now downloaded and ready for use
                    console.log(realm.objects("Student").length);
                  }
                );
              }
            }
          );

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
knethcommented, Aug 18, 2017

@Damnum It looks like we should have a label called “Chrome Debugger” to track our issues with it. I label it as a bug for now, and we will prioritize to give a better debugging experience.

0reactions
Damnumcommented, Aug 14, 2017

@kneth This happens on both Android and iOS, regardless of device or simulator. Specifically, Realm Collection Notifications simply stop working when turning on Chrome debugging (in addition to the empty realm problem). More problems with this are documented in #1089, #1095, #729, and others.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Realm swift: Empty realm after relaunching app - Stack Overflow
After investigating with Realm Studio I noticed that the default.realm is created just fine and objects are stored alright. When I stop running...
Read more >
New Realm.App({ id: appId }) produces an empty object
I'm using Realm for the first time for a React Native (created via react-native init) project, and I'm a bit confused as to...
Read more >
How to use the realm.open function in realm - Snyk
To help you get started, we've selected a few realm.open examples, based on popular ways it is used in public projects.
Read more >
Getting started with Realm for React Native | by mbvissers.eth
Open your cmd and create a new React Native app. npx react-native init RealmExample. Go into the new folder and run your app...
Read more >
Realm Database on Android: Getting Started
Realm, a persistence library by MongoDB, lets you easily store objects locally. In this tutorial, you'll create an app named PetRealm.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found