You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Mark Hahn <ma...@hahnca.com> on 2013/03/25 22:35:53 UTC

copy docs from one db to another?

I have a database with a zillion docs that I need to empty.  I just want
the design docs left behind.  I googled and saw some techniques that
require writing code.

Could I just GET the docs with curl and then PUT them?

Any other way to do it?

Re: copy docs from one db to another?

Posted by Nils Breunese <n....@vpro.nl>.
Mark Hahn wrote:

> I have a database with a zillion docs that I need to empty.  I just want
> the design docs left behind.  I googled and saw some techniques that
> require writing code.
> 
> Could I just GET the docs with curl and then PUT them?
> 
> Any other way to do it?

Drop the database, recreate it and put the design docs in again. I use couchapp/erica to manage design documents.

Nils.

Re: copy docs from one db to another?

Posted by Dave Cottlehuber <dc...@jsonified.com>.
On 25 March 2013 22:35, Mark Hahn <ma...@hahnca.com> wrote:
> I have a database with a zillion docs that I need to empty.  I just want
> the design docs left behind.  I googled and saw some techniques that
> require writing code.
>
> Could I just GET the docs with curl and then PUT them?
>
> Any other way to do it?

GET http://couch/db/_all_docs?startkey=%22_design/%22&endkey=%22_design0%22&include_docs=true
PUT/POST is left as an excercise to the gentle reader. Bulk docs is your friend.

You'll need to remove revs, and turn

{"total_rows":18075,"offset":352,"rows":[	
into
{"all_or_nothing": true, "docs": [


As Nils said, you should store all your ddocs in erica/couchapp form
under version control. Ditto the nodejs version.

This example uses erica, but couchapp would still do the job:

; list all ddocs
curl -sk http://couch/db/_all_docs\?startkey\=%22_design/%22\&endkey\=%22_design0%22
| jgrep --start rows -s "id"

; for each of the ddocs above clone them into a separate directory
erica clone http://host/db/_design/$ddoc $ddoc

IIRC erica doesn't support multiple ddocs in the same couchapp, I
could be wrong on that.

For these sorts of questions I usually look at the innards of futon e.g.:

https://github.com/apache/couchdb/blob/master/share/www/script/futon.browse.js#L404-L439

or you can dig with firebug/devtools as you like.

A+
Dave

Re: copy docs from one db to another?

Posted by Jeff Charette <io...@yahoo.com>.
You could make a view and list that added deleted to the docs then curl it's output to a file.  Then a call to bulk docs would do the trick.

Jeff Charette | Principal 
We Are Charette
web / identity / packaging

m  415.298.2707
w  wearecharette.com
e   jeffrey@wearecharette.com

On Mar 25, 2013, at 5:35 PM, Mark Hahn <ma...@hahnca.com> wrote:

> I have a database with a zillion docs that I need to empty.  I just want
> the design docs left behind.  I googled and saw some techniques that
> require writing code.
> 
> Could I just GET the docs with curl and then PUT them?
> 
> Any other way to do it?

Re: copy docs from one db to another?

Posted by Stephen Bartell <sn...@gmail.com>.
+1 this is how I do it.

Mark, use "doc_ids" query param when setting up the replication (http://couchdb.readthedocs.org/en/latest/api/misc.html?highlight=doc_ids#post-replicate)

On Mar 25, 2013, at 2:52 PM, Matthieu Rakotojaona <ma...@gmail.com> wrote:

> On Mon, Mar 25, 2013 at 10:35 PM, Mark Hahn <ma...@hahnca.com> wrote:
>> I have a database with a zillion docs that I need to empty.  I just want
>> the design docs left behind.  I googled and saw some techniques that
>> require writing code.
>> 
>> Could I just GET the docs with curl and then PUT them?
>> 
>> Any other way to do it?
> 
> 1. Named replication of the design docs to a "db-tmp"
> 2. Delete the "db" file (I assume you have access to the underlying files)
> 3. Replicate the other way around
> 
> 
> -- 
> Matthieu RAKOTOJAONA


Re: copy docs from one db to another?

Posted by Robert Newson <rn...@apache.org>.
http://wiki.apache.org/couchdb/Replication#Named_Document_Replication

On 25 March 2013 22:00, Mark Hahn <ma...@hahnca.com> wrote:
> Sorry to be an idiot, but how do i do a named replication?
>
>
>
> On Mon, Mar 25, 2013 at 2:52 PM, Matthieu Rakotojaona <
> matthieu.rakotojaona@gmail.com> wrote:
>
>> On Mon, Mar 25, 2013 at 10:35 PM, Mark Hahn <ma...@hahnca.com> wrote:
>> > I have a database with a zillion docs that I need to empty.  I just want
>> > the design docs left behind.  I googled and saw some techniques that
>> > require writing code.
>> >
>> > Could I just GET the docs with curl and then PUT them?
>> >
>> > Any other way to do it?
>>
>> 1. Named replication of the design docs to a "db-tmp"
>> 2. Delete the "db" file (I assume you have access to the underlying files)
>> 3. Replicate the other way around
>>
>>
>> --
>> Matthieu RAKOTOJAONA
>>

Re: copy docs from one db to another?

Posted by Mark Hahn <ma...@hahnca.com>.
Sorry to be an idiot, but how do i do a named replication?



On Mon, Mar 25, 2013 at 2:52 PM, Matthieu Rakotojaona <
matthieu.rakotojaona@gmail.com> wrote:

> On Mon, Mar 25, 2013 at 10:35 PM, Mark Hahn <ma...@hahnca.com> wrote:
> > I have a database with a zillion docs that I need to empty.  I just want
> > the design docs left behind.  I googled and saw some techniques that
> > require writing code.
> >
> > Could I just GET the docs with curl and then PUT them?
> >
> > Any other way to do it?
>
> 1. Named replication of the design docs to a "db-tmp"
> 2. Delete the "db" file (I assume you have access to the underlying files)
> 3. Replicate the other way around
>
>
> --
> Matthieu RAKOTOJAONA
>

Re: copy docs from one db to another?

Posted by Matthieu Rakotojaona <ma...@gmail.com>.
On Mon, Mar 25, 2013 at 10:35 PM, Mark Hahn <ma...@hahnca.com> wrote:
> I have a database with a zillion docs that I need to empty.  I just want
> the design docs left behind.  I googled and saw some techniques that
> require writing code.
>
> Could I just GET the docs with curl and then PUT them?
>
> Any other way to do it?

1. Named replication of the design docs to a "db-tmp"
2. Delete the "db" file (I assume you have access to the underlying files)
3. Replicate the other way around


-- 
Matthieu RAKOTOJAONA

Re: copy docs from one db to another?

Posted by Robert Newson <rn...@apache.org>.
If I'm not mistaken, that's exactly what Mark is asking about.

Yes, you can GET and PUT documents as a copy mechanism. That's all the
replicator does, after all.

B.

On 25 March 2013 21:46, Jens Alfke <je...@couchbase.com> wrote:
>
> On Mar 25, 2013, at 2:35 PM, Mark Hahn <ma...@hahnca.com>> wrote:
>
> I have a database with a zillion docs that I need to empty.  I just want
> the design docs left behind.
>
> If you delete the docs, you’ll leave behind tombstone revisions, so the database won’t strictly speaking be empty (unless you call purge afterwards.)
>
>  I googled and saw some techniques that
> require writing code.
> Could I just GET the docs with curl and then PUT them?
>
> The fastest way is probably
> 1. Create a new database
> 2. GET the design docs, PUT them to the new database
> 3. Delete the old database
> However you’ll be left with a database with a different name. I don’t think there is any API to rename a database.
>
> —Jens

Re: copy docs from one db to another?

Posted by Mark Hahn <ma...@hahnca.com>.
That's awesome.  I forgot futon could show an entire doc in json.

Now I have lots of ways to do it.


On Mon, Mar 25, 2013 at 3:11 PM, James Marca <jm...@translab.its.uci.edu>wrote:

> For a completely programming free approach, sometimes if I have, say
> just 2 or 3 design docs, I'll open them up in futon in the browser in
> separate tabs in the source view mode (so I can see the _rev field,
> etc).  Then in yet another tab, I delete the database, and then create
> create an empty database with the same name.  Then I go to each of the
> tabs, edit the design docs to get rid of the "_rev" field, and click
> save to write the design docs to the new db.
>
> It works and does exactly the same thing as getting the designdocs to
> a file, opening up the files, deleting the revision, and then using
> curl to PUT the docs in the new database
>
> I've tried the replication route too, but that got annoying pretty
> fast.  Better for me was to have a clean db with design docs stored so
> as to get a cannonical set of design docs without having to use my
> file system, but then I would cut and paste the design doc source via
> futon (create any old new document, replace its contents with the
> design doc contents (less the revision number), and click save.
>
> Quick and dirty, but it works okay.
>
> Regards,
> James
>
> On Mon, Mar 25, 2013 at 02:49:04PM -0700, Mark Hahn wrote:
> > thx
> >
> >
> >
> > On Mon, Mar 25, 2013 at 2:46 PM, Jens Alfke <je...@couchbase.com> wrote:
> >
> > >
> > > On Mar 25, 2013, at 2:35 PM, Mark Hahn <mark@hahnca.com<mailto:
> > > mark@hahnca.com>> wrote:
> > >
> > > I have a database with a zillion docs that I need to empty.  I just
> want
> > > the design docs left behind.
> > >
> > > If you delete the docs, you’ll leave behind tombstone revisions, so the
> > > database won’t strictly speaking be empty (unless you call purge
> > > afterwards.)
> > >
> > >  I googled and saw some techniques that
> > > require writing code.
> > > Could I just GET the docs with curl and then PUT them?
> > >
> > > The fastest way is probably
> > > 1. Create a new database
> > > 2. GET the design docs, PUT them to the new database
> > > 3. Delete the old database
> > > However you’ll be left with a database with a different name. I don’t
> > > think there is any API to rename a database.
> > >
> > > —Jens
> > >
>

Re: copy docs from one db to another?

Posted by James Marca <jm...@translab.its.uci.edu>.
For a completely programming free approach, sometimes if I have, say
just 2 or 3 design docs, I'll open them up in futon in the browser in
separate tabs in the source view mode (so I can see the _rev field,
etc).  Then in yet another tab, I delete the database, and then create
create an empty database with the same name.  Then I go to each of the
tabs, edit the design docs to get rid of the "_rev" field, and click
save to write the design docs to the new db.

It works and does exactly the same thing as getting the designdocs to
a file, opening up the files, deleting the revision, and then using
curl to PUT the docs in the new database

I've tried the replication route too, but that got annoying pretty
fast.  Better for me was to have a clean db with design docs stored so
as to get a cannonical set of design docs without having to use my
file system, but then I would cut and paste the design doc source via
futon (create any old new document, replace its contents with the
design doc contents (less the revision number), and click save.  

Quick and dirty, but it works okay.

Regards, 
James

On Mon, Mar 25, 2013 at 02:49:04PM -0700, Mark Hahn wrote:
> thx
> 
> 
> 
> On Mon, Mar 25, 2013 at 2:46 PM, Jens Alfke <je...@couchbase.com> wrote:
> 
> >
> > On Mar 25, 2013, at 2:35 PM, Mark Hahn <mark@hahnca.com<mailto:
> > mark@hahnca.com>> wrote:
> >
> > I have a database with a zillion docs that I need to empty.  I just want
> > the design docs left behind.
> >
> > If you delete the docs, you’ll leave behind tombstone revisions, so the
> > database won’t strictly speaking be empty (unless you call purge
> > afterwards.)
> >
> >  I googled and saw some techniques that
> > require writing code.
> > Could I just GET the docs with curl and then PUT them?
> >
> > The fastest way is probably
> > 1. Create a new database
> > 2. GET the design docs, PUT them to the new database
> > 3. Delete the old database
> > However you’ll be left with a database with a different name. I don’t
> > think there is any API to rename a database.
> >
> > —Jens
> >

Re: copy docs from one db to another?

Posted by Mark Hahn <ma...@hahnca.com>.
thx



On Mon, Mar 25, 2013 at 2:46 PM, Jens Alfke <je...@couchbase.com> wrote:

>
> On Mar 25, 2013, at 2:35 PM, Mark Hahn <mark@hahnca.com<mailto:
> mark@hahnca.com>> wrote:
>
> I have a database with a zillion docs that I need to empty.  I just want
> the design docs left behind.
>
> If you delete the docs, you’ll leave behind tombstone revisions, so the
> database won’t strictly speaking be empty (unless you call purge
> afterwards.)
>
>  I googled and saw some techniques that
> require writing code.
> Could I just GET the docs with curl and then PUT them?
>
> The fastest way is probably
> 1. Create a new database
> 2. GET the design docs, PUT them to the new database
> 3. Delete the old database
> However you’ll be left with a database with a different name. I don’t
> think there is any API to rename a database.
>
> —Jens
>

Re: copy docs from one db to another?

Posted by Jens Alfke <je...@couchbase.com>.
On Mar 25, 2013, at 2:35 PM, Mark Hahn <ma...@hahnca.com>> wrote:

I have a database with a zillion docs that I need to empty.  I just want
the design docs left behind.

If you delete the docs, you’ll leave behind tombstone revisions, so the database won’t strictly speaking be empty (unless you call purge afterwards.)

 I googled and saw some techniques that
require writing code.
Could I just GET the docs with curl and then PUT them?

The fastest way is probably
1. Create a new database
2. GET the design docs, PUT them to the new database
3. Delete the old database
However you’ll be left with a database with a different name. I don’t think there is any API to rename a database.

—Jens