Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destroying An Undefined Doc Removes the Whole Database #40

Closed
maggiejiangtda opened this issue Apr 13, 2017 · 3 comments
Closed

Destroying An Undefined Doc Removes the Whole Database #40

maggiejiangtda opened this issue Apr 13, 2017 · 3 comments

Comments

@maggiejiangtda
Copy link

Recently discovered a bug when trying to delete a doc from a CouchDB database. The action of deleting a document with "undefined" inputs actually removes the whole database. The .destroy() call should really be restricted to destroying documents and not the whole DB itself. If an undefined is sent in, I think nano should ideally return an error?

This is a sample code to reproduce what happens:

const nano = require( 'nano' )( CouchDB );
const dbName = nano.db.use( 'dbName' );

dbName.destroy( undefined, undefined, ( err ) => {
//DB is destroyed at this point
} );

@ramdesh
Copy link

ramdesh commented Jul 4, 2017

On close inspection, I found that the HTTP request that goes to the database if the id is undefined, is the same as the database delete request:
{ method: 'DELETE', headers: { 'content-type': 'application/json', accept: 'application/json' }, uri: 'https://{database-url}/{database-name}', qs: { rev: undefined } }

The two functions in nano, destroyDb and destroyDoc seem to build the same request URL when the ID is undefined.

@ColoradoFlyer
Copy link

This is the same issue I just opened (#181) -- with rather catastrophic results (deleting the entire _replicator database is kinda bad, IMHO).

Open for 2 years now?

@big-r81
Copy link
Contributor

big-r81 commented Jun 20, 2022

I'm closing this old ticket. If it's still a problem, please reopen or create a new ticket.

@big-r81 big-r81 closed this as completed Jun 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants