Skip to content

Instantly share code, notes, and snippets.

@eiri
Created October 26, 2017 16:38
Show Gist options
  • Save eiri/794d01a2b150c319cd2643f0cebebff5 to your computer and use it in GitHub Desktop.
Save eiri/794d01a2b150c319cd2643f0cebebff5 to your computer and use it in GitHub Desktop.
How to use COPY in CouchDB (with httpie)

How to use COPY in CouchDB

Create new db

$ http put :5984/names --auth admin:secret
{
    "ok": true
}

Give it to a default session's httpie user (in my case "eiri", the user have to be in _users db already)

$ http put :5984/names/_security admins:='{"names": ["eiri"], "roles": []}' --auth admin:secret
{
    "ok": true
}

Add two docs in the database

$ http put :5984/names/alice name=alice
{
    "id": "alice", 
    "ok": true, 
    "rev": "1-2350796167caec1f6ba70e9145a9e102"
}

$ http put :5984/names/bob name=bob
{
    "id": "bob", 
    "ok": true, 
    "rev": "1-c9f1576d06e12af51ece1bac75b26bad"
}

$ http :5984/names/bob
{
    "_id": "bob", 
    "_rev": "1-c9f1576d06e12af51ece1bac75b26bad", 
    "name": "bob"
}

Now copy alice over bob

$ http copy :5984/names/alice Destination:bob?rev=1-c9f1576d06e12af51ece1bac75b26bad
{
    "id": "bob", 
    "ok": true, 
    "rev": "2-bc4d8f5476abd7fbe1130e8409f29493"
}

$ http :5984/names/bob
{
    "_id": "bob", 
    "_rev": "2-bc4d8f5476abd7fbe1130e8409f29493", 
    "name": "alice"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment