Search a global realm for a user
Access a global realm in "/globalUsers" where the only schema is a "GlobalUser"
Uncaught exception in Realm Function: Error: Object type 'GlobalUser' not found in schema.
at Error (native)
at module.exports (handler.js:31:39)
at Object.listenerCallback (/usr/lib/node_modules/realm-object-server-professional/node_modules/realm-functions/lib/wrapper.js:85:7)
So it's weird. In the realm example code that's given after immediately creating a new function, I get the output after inserting a GlobalUser into the /globalUser realm:
Starting function
Changes in realm at: /globalUsers
Changes in Model: GlobalUser
object inserted at position 4 : RealmObject { username: 'test', email: '[email protected]' }
(see https://gist.github.com/michael-mckenna/312e0eea9449ef0c47700a943c1e7fc6 for the full function)
So everything seems to be good in the hood. In my code here however https://gist.github.com/michael-mckenna/76eedf5ce55db9e279098718b2ab26ae, the Realm Function is breaking at line 31. But as mentioned earlier, my model is in fact being recognized, the item is being inserted into the realm, and I just don't know where the discrepancy lies such that I'm getting this "GlobalUser" not found error.
@michael-mckenna What happens when you take them out of the functions and place them in their own stand-alone node script? As in node insertUser.js and node userSearch.js
@ianpward Better (no crash) - however, const accounts = accountsRealm.objects("GlobalUser"); is returning no objects, even though the objects are present on iOS and the Realm Browser.
How are you opening that realm? Most likely you need to use asyncOpen to complete the sync first and then run your query in the callback
We generally encourage the use of Realm.open or Realm.openAsync methods over using the constructor. We have only just updated the documentation though, so apologies about this not being clear. These two methods will make sure your realm synchronized before handing it over to you.
There will probably only be an issue the first time the function is called because the instance will be cached but given that this is a global realm that you want to access every time, I would probably choose to keep the realm instance in the outer scope.
Thanks for the tips. Everything seems to be good to go!
How are you opening that realm? Most likely you need to use
asyncOpento complete the sync first and then run your query in the callback
Thanks @ianpward before I even use this approach I know it's going to help. 馃挴
Most helpful comment
How are you opening that realm? Most likely you need to use
asyncOpento complete the sync first and then run your query in the callback