@@ -18,22 +18,30 @@ npm install orbit-db-docstore
1818const IPFS = require (' ipfs' )
1919const OrbitDB = require (' orbit-db' )
2020
21- const ipfs = new IPFS ()
22- const orbitdb = new OrbitDB (ipfs)
23- const docstore = orbitdb .docstore (' db name' )
24-
25- docstore .put ({ _id: ' hello world' , doc: ' all the things' })
26- .then (() => docstore .put ({ _id: ' sup world' , doc: ' other things' }))
27- .then (() => docstore .get (' hello' ))
28- .then ((value ) => console .log (value))
29- // [{ _id: 'hello world', doc: 'all the things'}]
21+ const ipfs = new IPFS ({ repo: ' orbitdb/ipfs' });
22+ ipfs .on (' ready' , () => {
23+ const orbitdb = new OrbitDB (ipfs);
24+ const docstore = orbitdb .docstore (' dbName' );
25+
26+ docstore .then (() => {
27+ docstore .put ({ _id: ' hello world' , doc: ' all the things' })
28+ .then (() => docstore .put ({ _id: ' sup world' , doc: ' other things' }))
29+ .then (() => docstore .get (' hello' ))
30+ .then ((value ) => console .log (value))
31+ // [{ _id: 'hello world', doc: 'all the things'}]
32+ })
33+ });
34+
35+ // or
36+ const docstore = await orbitdb .docstore (' dbName' );
37+ });
3038
3139```
3240
3341You can specify the field to index by in the options:
3442
3543``` javascript
36- const docstore = orbitdb .docstore (' db name ' , { indexBy: ' doc' })
44+ const docstore = await orbitdb .docstore (' dbName ' , { indexBy: ' doc' })
3745
3846docstore .put ({ _id: ' hello world' , doc: ' some things' })
3947 .then (() => docstore .put ({ _id: ' hello universe' , doc: ' all the things' }))
@@ -46,7 +54,7 @@ docstore.put({ _id: 'hello world', doc: 'some things' })
4654You can also use a mapper to query the documents
4755
4856``` javascript
49- const docstore = orbitdb .docstore (' db name ' )
57+ const docstore = await orbitdb .docstore (' dbName ' )
5058
5159docstore .put ({ _id: ' hello world' , doc: ' some things' , views: 10 })
5260 .then (() => docstore .put ({ _id: ' hello universe' , doc: ' all the things' , views: 100 }))
0 commit comments