Namespace: Databases-Documents

Databases.Databases-Documents

Documents database.

Source:

Example

Create documents db with custom index

import { createHelia } from 'helia'
import { createOrbitDB, Documents } from 'orbitdb'

const ipfs = createHelia()
const orbitdb = await createOrbitDB({ ipfs })
const db = await orbitdb.open('my-docs', { Database: Documents({ indexBy: 'myCustomId'} ) }

Extends

Methods

(async) all()

Returns all documents.

Source:
Returns:

[][string, string, string] An array of documents as hash/key value entries.

(async) del(key) → {string}

Deletes a document from the store.

Parameters:
Name Type Description
key string

The key of the doc to delete.

Source:
Returns:

The hash of the new oplog entry.

Type
string

(async) get(key) → {Object}

Gets a document from the store by key.

Parameters:
Name Type Description
key string

The key of the doc to get.

Source:
Returns:

The doc corresponding to key or null.

Type
Object

(async, generator) iterator(filtersopt)

Iterates over documents.

Parameters:
Name Type Attributes Default Description
filters Object <optional>
{}

Various filters to apply to the iterator.

Properties
Name Type Attributes Default Description
amount string <optional>
-1

The number of results to fetch.

Source:
Yields:
[string, string, string] The next document as hash/key/value.

(async) put(doc) → {string}

Stores a document to the store.

Parameters:
Name Type Description
doc Object

An object representing a key/value list of fields.

Source:
Returns:

The hash of the new oplog entry.

Type
string

(async) query(findFn) → {Array}

Queries the document store for documents matching mapper filters.

Parameters:
Name Type Description
findFn function

A function for querying for specific results.

The findFn function's signature takes the form function(doc) where doc is a document's value property. The function should return true if the document should be included in the results, false otherwise.

Source:
Returns:

Found documents.

Type
Array