apache / couchdb-nano

Nano: The official Apache CouchDB library for Node.js
https://www.npmjs.com/package/nano
Apache License 2.0
651 stars 165 forks source link

Can I create a couchdb database with shard param? #228

Closed hmdevelopermind closed 4 years ago

hmdevelopermind commented 4 years ago

If I want to create a couch db with curl setting a shard number I need I do it this way:

curl -X PUT http://test:test@127.0.0.1:5984/test-1?q=20

However when I create a db using nano I do not know how to pass q=20. Is it possible to do so in Nano?

janl commented 4 years ago

Looks like you can pass options: https://github.com/apache/couchdb-nano/blob/master/lib/nano.js#L353

Can you try this: nano.db.create('foo', {q:1})?

hmdevelopermind commented 4 years ago

@janl Thanks a lot yes that worked. :) A quick question when I pass this: this._db.create(databaseName, {q:10, n:5}). I can see q is 10 for created db but n is is still 1 rather than 5. However I do n ot think it is a nano issue as when I do the same with curl still n is 1. Is there any criteria for running couch to be able to set n to a higher number? Because by convention they say n should be q/2 so if my q is 10 I want n to be 5

wohali commented 4 years ago

If it is a single, standalone server, you can't change n from its default value of 1.

CouchDB won't allow creation of multiple replicas on a single server. To have 5 copies, you'd need at least 5 servers in your cluster.

Also, nowhere do we recommend that n should be q/2. By default, on a 3-node cluster, CouchDB 2.x creates q=8, n=3 databases, and 3.x uses q=2, n=3.

hmdevelopermind commented 4 years ago

Thank you 🙏