@@ -18,22 +18,30 @@ npm install orbit-db-docstore
18
18
const IPFS = require (' ipfs' )
19
19
const OrbitDB = require (' orbit-db' )
20
20
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
+ });
30
38
31
39
```
32
40
33
41
You can specify the field to index by in the options:
34
42
35
43
``` javascript
36
- const docstore = orbitdb .docstore (' db name ' , { indexBy: ' doc' })
44
+ const docstore = await orbitdb .docstore (' dbName ' , { indexBy: ' doc' })
37
45
38
46
docstore .put ({ _id: ' hello world' , doc: ' some things' })
39
47
.then (() => docstore .put ({ _id: ' hello universe' , doc: ' all the things' }))
@@ -46,7 +54,7 @@ docstore.put({ _id: 'hello world', doc: 'some things' })
46
54
You can also use a mapper to query the documents
47
55
48
56
``` javascript
49
- const docstore = orbitdb .docstore (' db name ' )
57
+ const docstore = await orbitdb .docstore (' dbName ' )
50
58
51
59
docstore .put ({ _id: ' hello world' , doc: ' some things' , views: 10 })
52
60
.then (() => docstore .put ({ _id: ' hello universe' , doc: ' all the things' , views: 100 }))
0 commit comments