Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upFAQ: My data isn't appearing! An explanation of db.load() vs db.events.on("replicated", callback) #579
Labels
Comments
|
Leaving it here but flagging as potential to transfer to the Field Manual. Maybe we can replace this pinned issue with just a link to the Field Manual and a quick blurb. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's been a number of questions lately about data not appearing in the store when you expect, so I thought it would be a good time to take a second to explain the process of opening a database and getting data out of it. The database can be either local or remote.
Important Note: While content discovery can happen via the IPFS distributed hash table, due to the limitations of browser-based IPFS nodes, it's still best if the necessary peers are directly connected via a call to
ipfs.swarm.connectThe basic flow of data can be summarized as follows:
orbitdb.openwith default options (or its various shorthand methodsorbitdb.keyvalue,orbitdb.docsetc) will create a local database and database manifest in the IPFS instance that OrbitDB is interacting with. In traditional database parlance, you can view this as creating an empty schema.db.loadfor both local and remote databases which loads data from the local IPFS into memory for use. Basically it's saying, "give me the data this node knows about"listenerFunctionand register it as an event listener ondb.events.on('replicated', function listenerFunction() {}). This will be fired when data is loaded from a remote source, and again every time those remote data change.In code, this might look something like:
Feel free to respond to this issue with further questions! We want to make sure we're explaining this properly.