Create a database
new PouchDB([name], [options])
This method creates a database or opens an existing one. If you use a URL like dbname, then PouchDB will work as a client to an online CouchDB instance. Otherwise it will create a local database using whatever backend is present.
Options
- name: You can omit the name argument and specify it via options instead. Note that the name is required.
Options for local databases:
- auto_compaction: This turns on auto compaction, which means compact() is called after every change to the database. Defaults to false.
- adapter: One of 'idb', 'leveldb', or 'http'.
- revs_limit: Specify how many old revisions we keep track (not a copy) of. Specifying a low value means Pouch may not be able to figure out whether a new revision received via replication is related to any it currently has which could result in a conflict. Defaults to 1000.
- deterministic_revs: Use a md5 hash to create a deterministic revision number for documents. Setting it to false will mean that the revision number will be a random UUID. Defaults to true.
Options for remote databases:
- fetch(url, opts): Intercept or override the HTTP request, you can add or modify any headers or options relating to the http request then return a new fetch Promise.
- auth.username + auth.password: You can specify HTTP auth parameters either by using a database with a name in the form http://user:pass@host/name or via the auth.username + auth.password options.
- skip_setup: Initially PouchDB checks if the database exists, and tries to create it, if it does not exist yet. Set this to true to skip this setup.
Notes:
- In IndexedDB PouchDB will use _pouch_ to prefix the internal database names. Do not manually create databases with the same prefix.
- When acting as a client on Node, any other options given will be passed to request.
- When using the 'leveldb' adapter (the default on Node), any other options given will be passed to levelup.
Example Usage:
var db = new PouchDB('dbname');
// or
var db = new PouchDB('http://localhost:5984/dbname');
Create an in-memory Pouch (must install pouchdb-adapter-memory first):
var db = new PouchDB('dbname', {adapter: 'memory'});
Create a remote PouchDB with special fetch options:
var db = new PouchDB('http://example.com/dbname', {
fetch: function (url, opts) {
opts.headers.set('X-Some-Special-Header', 'foo');
return PouchDB.fetch(url, opts);
}
});