8

On iOS, it is possible to inspect the contents of a Realm database by opening the corresponding file with the Realm Browser. The path to that file can be printed by using the following line of code (as noted here):

print(Realm.Configuration.defaultConfiguration.path)

Is it possible to do the same when using the React Native version of Realm?

Community
  • 1
  • 1
nburk
  • 22,409
  • 18
  • 87
  • 132

4 Answers4

10

Just found the answer myself by digging through the docs:

console.log('create db:', db.path)
nburk
  • 22,409
  • 18
  • 87
  • 132
  • do I need to copy that file to my pc and open it with Realm Browser every time I the Realm file is updated? or there is way to connect Realm Browser with the application realm db? – Mostafiz Rahman Feb 13 '18 at 12:51
7

Just in case you can't get the above to work. Here is how I did it:

1) import the file in which you define the schema and create a new realm into a component that will mount when you refresh the simulator.

import realm from './path_to_file_where_realm created'

2) console.log(realm.path) in the componentWillMount() lifecycle method & enable remote debugging to see the output.

3) open up realm browser and click open realm file. Command Shift G on mac will let you paste in the path from the console.log

click on the realm file to open it with the realm browser.

Also for those not familiar with the realm browser, it can be found here. It just lets you see & edit data in your realm with a graphical interface.

LuckyLukas
  • 465
  • 2
  • 6
  • 18
5

In my case i used,

const Realm = require('realm');
console.log('REALM PATH', Realm.defaultPath);
Daniel Mesa
  • 126
  • 1
  • 2
  • 1
    Please give a more detailed explanation demonstrating how/why what you've suggested is the answer to the problem. – rst-2cv Jun 29 '18 at 13:49
0

To elaborate on Daniel Mesa's answer:

In your react native class (assuming ES6 here) below your import lines (above the class definition) add the following:

const Realm = require('realm');

Then add a componentDidMount function and log the Realm default path:

  componentDidMount() {
    console.log('REALM PATH', Realm.defaultPath);
  }

This should then output the realm db path in the console log (debug your react native app).

Trevor
  • 1,561
  • 1
  • 20
  • 28