Open maroodb opened 6 years ago
I believe you need to call load()
on the database before you try to get
something. In other words you need to tell it to replicate all the data, before you will have any data locally that you can get.
(also, it's await orbitdb.docstore
, I think)
Something like:
db = await orbitdb.docstore('/orbitdb/QmPmh5G7kUVTCAAeRCaZmdN8zeDbMByf3oU41xA1Cx5cw9/my-db');
db.load();
console.log(db.get('mydoc'));
I believe what @coyotespike writes above is the solution here.
@maroodb any updates? Did you manage to get it working?
Maybe it's the same problem I'm experiencing here.
I set orbitdb in 3 different machines.
const db = await orbitdb.docstore('sample-db', access);
All nodes receive the data as expected when I add a new doc in any of the browsers. The problem happens when I create a new doc on the nodejs script. It is populated locally but it isn't replicated to the browsers.
I put both files here.
(I know the script naming I gave is not the best one as the idea here is to get rid of the server-client model...)
@adrprado You may need to more directly connect the nodejs databases to the browser database. You can do this by putting the nodejs machines' IPFS multiaddress into the browser's IPFS bootstrap list. There is a blog post in orbitdb/orbit-db#314 that will be helpful.
@coyotespike, thanks for the tip. I talked with Mark and he also couldn't figure out why the browser node won't sync with the nodejs script.
He suggested a few things, but it seems everything is in place. I'm running a local signal server (rendezvous), I checked the swarm.peers(), pubsub.peers(), and the nodes are populated with each other id, as expected.
I also ran tcpdump and see activity on both sides as well (all traffic routed by the signal server).
And I have the same version of IPFS and OrbitDB on both nodes.
To sum up:
const db = await orbitdb.docstore('sample-db', access);
const orbitdb = new OrbitDB('/orbitdb/Qm..bR/sample-db')
;thanks @coyotespike it works in CLI .. @haadcode Sorry for being late to give update
@maroodb great to hear it's now working for you!
@adrprado sound like you're experiencing a different problem and I'd love to understand why it's not working. Specifically this part sounds like there's some glitch somewhere:
When I add a new doc on Browser 1, Browser 2 and Nodejs replicate the data locally. When I add a new doc on Nodejs, both browsers won't replicate the new doc.
If the browser-added doc gets replicated to the nodejs node, it sounds like they're talking. But since the nodejs-added doc doesn't get to the browsers, it sounds like there's something off in the way they're talking. This could be on OrbitDB side or on IPFS side. The browser-nodejs part hasn't been used and tested much so I'd love to understand what we need to fix here in order to get it working smoothly.
@adrprado if you have any insight or more details of the behaviour you're seeing, please do share your notes. I'd be curios to hear if (in the same example script ^), if the nodejs and browser nodes can, for example, get each other's messages over pubsub (ipfs.pubsub.subscribe('something', ...), ipfs.pubsub.publish('something', 'hello?') and if it works two ways (from browser to nodejs and nodejs to browser).
Hi @haadcode, I'm enabling the debug on your code (locally) so I can check all the messaging exchange and I will let you know if I see something that's preventing this sync from nodejs to the browsers.
Moving to the Field Manual for deeper discussion
Hello World!
I'm trying replicating my public database in another computer using the address "/orbitdb/QmPmh5G7kUVTCAAeRCaZmdN8zeDbMByf3oU41xA1Cx5cw9/my-db". db = await orbitdb.docs('/orbitdb/QmPmh5G7kUVTCAAeRCaZmdN8zeDbMByf3oU41xA1Cx5cw9/my-db');
and when I try to get an existing object I got empty document .