Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7794081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:41:11+00:00 2026-06-01T22:41:11+00:00

Is it possible to delete all documents in a couchdb database, except design documents,

  • 0

Is it possible to delete all documents in a couchdb database, except design documents, without creating a specific view for that?

My first approach has been to access the _all_docs standard view, and discard those documents starting with _design. This works but, for large databases, is too slow, since the documents need to be requested from the database (in order to get the document revision) one at a time.

If this is the only valid approach, I think it is much more practical to delete the complete database, and create it from scratch inserting the design documents again.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T22:41:13+00:00Added an answer on June 1, 2026 at 10:41 pm

    I can think of a couple of ideas.

    Use _all_docs

    You do not need to fetch all the documents, only the ID and revisions. By default, that is all that _all_docs returns. You can make a pretty big request in a batch (10k or 100k docs at a time should be fine).

    Replicate then delete

    You could use an _all_docs query to get the IDs of all design documents.

    GET /db/_all_docs?startkey="_design/"&endkey="_design0"
    

    Then replicate them somewhere temporary.

    POST /_replicator
    
    { "source":"db", "target":"db_ddocs", "create_target":true
    , "user_ctx": {"roles":["_admin"]}
    , "doc_ids": ["_design/ddoc_1", "_design/ddoc_2", "etc..."]
    }
    

    Now you can just delete the original database and replicate the temporary one back by swapping the "source" and "target" values.

    Deleting vs “deleting”

    Note, these are really apples vs. oranges techniques. By deleting a database, you are wiping out the edit history of all its documents. In other words, you cannot replicate those deletion events to any other database. When you “delete” a document in CouchDB, it stores a record of that deletion. If you replicate that database, those deletions will be reflected in the target. (CouchDB stores “tombstones” indicating the document ID, its revision history, and its deleted state.)

    That may or may not be important to you. The first idea is probably considered more “correct” however I can see the value of the second. You can visualize the entire program to accomplish this in your head. It’s only a few queries and you’re done. No looping through _all_docs batches, no headache. Your specific situation will probably make it obvious which is better.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to delete all lines that have the same first 30 characters
Is it possible to delete all data in the database using NHibernate. I want
Possible Duplicate: What's the best way to delete all data from a table? Clear
Is it possible to delete all embed, object, script tags in php?
Is it possible to delete all untracked files from my working directory? Let's say
I erroneously delete all the rows from a MS SQL 2000 table that is
Is possible delete all the records from a TClientDataset at once?
Possible Duplicate: Delete all but the most recent X files in bash I have
Is it possible to delete a cell with swipe action on it ? Or
Is it possible to delete some images from the browser (firefox2) memory using javascript?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.