15

So I want to replicate some changes I made to my design files from dev to production (a.k.a. I want to deploy something).

I'm somehow confused since my research did not lead to any concrete results. Although this seams IMHO like a pretty obvious use case.

Am I missing something?

Aron Woost
  • 19,268
  • 13
  • 43
  • 51

3 Answers3

18

You can specify the document IDs to replicate, without having to write a filter. Post the replication document (or command) like so:

{ "source": "my_db"
, "target": "http://target:5984/target_db"
, "doc_ids": [ "_design/my_ddoc" ]
}
JasonSmith
  • 72,674
  • 22
  • 123
  • 149
  • Also the way faster solution. Thanks! – Aron Woost Sep 08 '11 at 07:53
  • 1
    Make sure you are using admin user for the replication to succeed under target pass user/pass in the url "target":"http://admin:password@ip/db" , only admins can create design documents – doron aviguy May 21 '16 at 07:43
9

You can use 'Filtered Replication' (See http://wiki.apache.org/couchdb/Replication#Filtered_Replication for details)

Basically, you'll supply a function that returns true for design documents like;

function(doc, req) {
  return "_design/" === doc._id.substr(0, 8)
}

and then add "filter":"ddocname/filtername" to your _replicate request body.

Robert Newson
  • 4,631
  • 20
  • 18
  • In this case you probably want to just replicate the named ID as shown by JasonSmith and not perform a more general replication. – Ewan Makepeace Sep 07 '11 at 03:18
  • 1
    Robert's solution most directly answers the question. In my solution, you must know the document IDs. In his, CouchDB figures that out for you. I think in practice, people do indeed know their design document ids however. – JasonSmith Sep 09 '11 at 07:00
  • I have found filters to be very slow. Using the name of the design doc is better for most cases. – Mike McKay Jun 09 '12 at 20:06
  • This fits a database-per-user pattern pretty well. Especially if you're already doing a filtered replication to populate the new users database. – MrYellow Jan 24 '15 at 02:03
1

I keep my design documents stored as .js files on disk. Then I use couchdb-update-views to update the design documents on a server

npm install -g couchdb-update-views
couchdb-update-views --config /path/to/config.json --docsDir /path/to/design/docs/directory/
Noah
  • 33,851
  • 5
  • 37
  • 32