orbitdb icon indicating copy to clipboard operation
orbitdb copied to clipboard

unable to query database created by another project

Open sdelvalle57 opened this issue 6 years ago • 8 comments

Hi there.

Im creating an instance of orbitDb inside a webservice that at the moment is running locally:

        const orbitdb = await OrbitDB.createInstance(ipfs);
        this.db = await orbitdb.docstore(dbName, { indexBy: 'uid', accessController: {write: ['*']}});
        await this.db.load();
        
        await this.db.put({uid: 65678}, { pin: true })
        const all = this.db.query((doc: any) => doc)
        console.log(all)
        console.log(this.db.address.toString())

the response from last two logs are:

        [ { uid: 65678 } ]
        /orbitdb/zdpuAnZdSPcLf3PGRDWLDQG82EZoCDWJLhpBFkBPKhMaukTh2/localhost_bf_10

But when I try to access that DB from another project running in localhost too, I get nothing:

        console.log(OrbitDB.isValidAddress(dbId.data.response))
        const db = await orbitdb.docstore(dbId.data.response, { indexBy: 'uid' });
        await db.load();
        const all = await db.query((doc) => doc)
        console.log(all)

the response is an empty array. Any help? Thanks!

sdelvalle57 avatar Jan 13 '20 09:01 sdelvalle57

Just out of curiosity, are you using the same ipfs instance to run both of the orbitdb instances? This tends to be buggy as pubsub doesn't work well in this configuration. If not can you use swarm connect to confirm the two ipfs instances are able to comunicate?

phillmac avatar Jan 13 '20 12:01 phillmac

Im now running 2 connected IPFS nodes on the same machine, however Im still unable to load the DB on the second machine. Wanted also to point something, when I create the DB on the web service running locally, it creates an orbitdb folder on the root of the project, maybe it is not replicating to other peers:

imagen

Any help on how can I replicate this DB to peers?

sdelvalle57 avatar Jan 14 '20 10:01 sdelvalle57

Hey @sdelvalle57, which versions of ipfs and orbitdb are you using? The ./orbitdb folder is the default directory if none is specified so that shouldn't be a problem.

Does console.log(OrbitDB.isValidAddress(dbId.data.response)) print true? What's the content of dbId.data.response?

philmac is right that if the IPFS aren't able to communicate to DB won't replicate so would be good to confirm that they are connected

shamb0t avatar Jan 14 '20 12:01 shamb0t

ipfs version 0.4.22 ipfs-http-client: "^37.0.2", orbit-db: "^0.22.0",

´console.log(OrbitDB.isValidAddress(dbId.data.response)) = true´ ´dbId.data.response = /orbitdb/zdpuAwd71aFi1HKhAwsQVzf554FoMnYnK99tFaHUEwuL3D5c3/localhost_bf_13´

IPFS nodes are connected to each other!

sdelvalle57 avatar Jan 15 '20 00:01 sdelvalle57

What about ipfs.swarm.connect(<other ipfs peer>) ?

phillmac avatar Jan 15 '20 00:01 phillmac

already did that, and confirmed with console.log(await (ipfs.swarm.peers()))`

sdelvalle57 avatar Jan 15 '20 04:01 sdelvalle57

on the server side I run this:

       const orbitdb = await OrbitDB.createInstance(ipfs);
        this.db = await orbitdb.docstore(dbName, { indexBy: 'uid', accessController: {write: ['*']}});

        this.db.events.on('replicated', () => {
            const all = this.db.query((doc: any) => doc)
            console.log(all)
        })
        this.db.events.on('replicate', () => {
            console.log("replcate");
            const all = this.db.query((doc: any) => doc)
            console.log(all)
        })
        await this.db.put({uid: 65678}, { pin: true })

but nothing is fired after I add content to the DB

sdelvalle57 avatar Jan 15 '20 04:01 sdelvalle57

did you solve the problem? I have the same problem

FredyVia avatar May 15 '21 05:05 FredyVia

Please try with the latest version of OrbitDB. If problems persist, feel free to re-open this issue.

haydenyoung avatar Sep 17 '23 10:09 haydenyoung