Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FAQ: My data isn't appearing! An explanation of db.load() vs db.events.on("replicated", callback) #579

Open
aphelionz opened this issue Mar 8, 2019 · 1 comment
Labels

Comments

@aphelionz
Copy link
Contributor

@aphelionz aphelionz commented Mar 8, 2019

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.connect

The basic flow of data can be summarized as follows:

  1. Calling orbitdb.open with default options (or its various shorthand methods orbitdb.keyvalue, orbitdb.docs etc) 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.
  2. You'll want to then call db.load for 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"
  3. For remote databases, you'll need to define a listenerFunction and register it as an event listener on db.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:

var db = await orbitdb.keyvalue(dbAddress)
await db.load() // Database contents are now in memory
db.events.on("replicated", () => {
  // any remote database content is now replicated to your IPFS node
})

Feel free to respond to this issue with further questions! We want to make sure we're explaining this properly.

@aphelionz aphelionz pinned this issue Mar 8, 2019
@aphelionz aphelionz changed the title FAQ: My data isn't appearing! An explanation of db.load() vs db.events.on("replicate", callback) FAQ: My data isn't appearing! An explanation of db.load() vs db.events.on("replicated", callback) Mar 8, 2019
@aphelionz
Copy link
Contributor Author

@aphelionz aphelionz commented Sep 27, 2019

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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.