PouchDB plugin for a document-bound API
npm install pouchdb-doc-api> PouchDB plugin for a document-bound API




``js
var db = new PouchDB('mydb')
var docId = 'mydocid' // can be any valid do id
var api = db.doc(docId)
// creates or replaces existing document with _id: mydocid
api.set({foo: 'bar'})
.then(() => {
// loads document with _id: mydocid
return api.get()
})
.then((doc) => {
// removes document with _id: mydocid
return api.unset()
})
`
In case you want to store sensitive data, be aware that PouchDB does not remove
data but creates new revisions. The older revisions remain accessible.
The only exception to this are local documents
with an docId prefixed by _local/. So say you want to store an API key orpouchdb-doc-api
session ID using , I strongly recommend to us a docId like_local/session. Full usage example
`js`
var db = new PouchDB('mydb')
var api = db.doc('_local/session')
api.set and api.unset will no remove previously stored data without leaving
revisions that could be recovered.
- Factory
- store.get()
- store.set()
- store.unset
Returns the store API bound to the document with the passed id
`js`
db.doc(id)
| Argument | Type | Description | Required |
|---|---|---|---|
id | String | ID of the document the store API should be bound to. | Yes |
Example
`js`
var db = new PouchDB('mydb')
var store = db.doc('mydocid')
Resolves with the document properties, without the _id and _rev properties.
`js`
store.get().then((properties) => {})
Replaces all current document properties with the once passed. _id and _rev
properties are ignored. Resolves with the document properties.
`js`
store.set({foo: 'bar'}).then((properties) => {})
Removes document from the database using PouchDB’s db.remove()
method. Resolves without arguments.
`js``
store.unset().then(() => {})