docs/_includes/api/create_database.html
{% include anchor.html edit="true" title="Create a database" hash="create_database" %} {% highlight "js" %} new PouchDB([name], [options]) {% endhighlight %} This method creates a database or opens an existing one. If you use a URL like 'http://domain.com/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 'indexeddb', '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. * view_update_changes_batch_size: Specify how many change records will be consumed at a time when rebuilding view indexes when the query() method is used. Defaults to 50. * view_adapter: Specify a different adapter to store the view index data. * purged_infos_limit: Specify how many purged revisions we keep track of. Specifying a low value can result in Pouch not delegating older purges down to views. Defaults to 1000. **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:** 1. In IndexedDB PouchDB will use _pouch_ to prefix the internal database names. Do not manually create databases with the same prefix. 2. When acting as a client on Node, any other options given will be passed to [request][]. 3. When using the 'leveldb' adapter (the default on Node), any other options given will be passed to [levelup][]. 4. If you are using the jwt auth handler, please use the fetch option to add the required headers and handle connected logic like token refreshes. [request]: https://github.com/mikeal/request [levelup]: https://github.com/rvagg/node-levelup [levelup_options]: https://github.com/rvagg/node-levelup/#options #### Example Usage: {% highlight "js" %} const db = new PouchDB('dbname'); // or const db = new PouchDB('http://localhost:5984/dbname'); {% endhighlight %} Create an in-memory Pouch (must install pouchdb-adapter-memory first): {% highlight "js" %} const db = new PouchDB('dbname', {adapter: 'memory'}); {% endhighlight %} Create a remote PouchDB with special fetch options: {% highlight "js" %} const db = new PouchDB('http://example.com/dbname', { fetch: function (url, opts) { opts.headers.set('X-Some-Special-Header', 'foo'); return PouchDB.fetch(url, opts); } }); {% endhighlight %} For more info, check out adapters.