CouchDB Cheat Sheet

CouchDB is a NoSQL database that uses a document-oriented approach for storing and retrieving data. This cheatsheet is a quick reference guide for common CouchDB operations and commands.

Table of Contents

No.Operation/CommandSyntax
1.Install CouchDBsudo apt-get install couchdb
2.Start/Stop CouchDBsudo service couchdb start
sudo service couchdb stop
3.Access CouchDB Fauxton (Web UI)http://localhost:5984/_utils/
4.Create a Databasecurl -X PUT http://localhost:5984/mydatabase
5.List All Databasescurl http://localhost:5984/_all_dbs
6.Delete a Databasecurl -X DELETE http://localhost:5984/mydatabase
7.Insert a Documentcurl -X POST http://localhost:5984/mydatabase -d '{"key": "value"}'
8.Retrieve a Documentcurl http://localhost:5984/mydatabase/document_id
9.Update a Documentcurl -X PUT http://localhost:5984/mydatabase/document_id -d '{"new_key": "new_value"}'
10.Delete a Documentcurl -X DELETE http://localhost:5984/mydatabase/document_id?rev=document_revision
11.Bulk Insert Documentscurl -X POST http://localhost:5984/mydatabase/_bulk_docs -d '{"docs": [{"key": "value1"}, {"key": "value2"}]}'
12.Create a Design Documentcurl -X PUT http://localhost:5984/mydatabase/_design/mydesign -d '{"views": {"myview": {"map": "function(doc) { emit(doc._id, null); }"}}}'
13.Query a Viewcurl http://localhost:5984/mydatabase/_design/mydesign/_view/myview
14.Replication - Create a Replication Documentcurl -X POST http://localhost:5984/_replicate -d '{"source": "http://source_db_url", "target": "http://target_db_url"}'
15.Compact a Databasecurl -X POST http://localhost:5984/mydatabase/_compact
16.View Database Informationcurl http://localhost:5984/mydatabase
17.Create a Usercurl -X PUT http://localhost:5984/_users/org.couchdb.user:newuser -d '{"name": "newuser", "password": "password", "roles": [], "type": "user"}'
18.List All Userscurl http://localhost:5984/_users/_all_docs
19.Delete a Usercurl -X DELETE http://localhost:5984/_users/org.couchdb.user:newuser?rev=user_revision
20.Security - Create an API Keycurl -X POST http://localhost:5984/_api/v2/db/mydatabase/_security/apiKeys -H "Authorization: Basic base64(username:password)"
21.View Active Taskscurl http://localhost:5984/_active_tasks
22.Configure CouchDBEdit the local.ini configuration file.
23.Backup a Databasecurl -X POST http://localhost:5984/_replicate -d '{"source": "http://localhost:5984/mydatabase", "target": "backup_location"}'
24.Restore a Databasecurl -X POST http://localhost:5984/_replicate -d '{"source": "backup_location", "target": "http://localhost:5984/mydatabase"}'
25.Check CouchDB Versioncurl http://localhost:5984
26.View Logstail -f /opt/couchdb/var/log/couchdb/couch.log
27.Enable CORSEdit the local.ini configuration file and add the necessary CORS configurations.
28.Change Admin Passwordcurl -X PUT http://localhost:5984/_config/admins/admin -d '"new_password"'
29.MapReduce ExampleCreate map and reduce functions in a design document.
30.Compact Viewcurl -X POST http://localhost:5984/mydatabase/_compact/mydesign/myview