Voir aussi :
Voir :
Code :
docker run -d --name my-couchdb -p 5984:5984 -e COUCHDB_USER=admin -e COUCHDB_PASSWORD=password couchdb:3.2.1
WebUI Fauxton Futon
Ping
curl http://admin:password@127.0.0.1:5984
Pour Supervision
curl http://localhost:5984/_up
Show databases
curl http://admin:password@localhost:5984/_all_dbs
Create database
curl -X PUT http://127.0.0.1:5984/testdb
Show all docs
curl http://admin:password@localhost:5984/testdb/_all_docs curl http://admin:password@localhost:5984/testdb/_all_docs?include_docs=true
Upload binary file
curl -X PUT http://127.0.0.1:5984/albums/6e1295ed6c29495e54cc05947f18c8af/ artwork.jpg?rev=2-2739352689 --data-binary @artwork.jpg -H "Content-Type: image/jpg"
Opérandes de comparaison
https://guide.couchdb.org/draft/tour.html
https://dev.to/yenyih/query-in-apache-couchdb-mango-query-lfd
{ "selector": { "status": { "$eq": "draft" } }, "fields": ["_id", "_rev", "title", "content", "date", "author"], "sort": [], "limit": 10, "skip": 0, "execution_stats": true }
Bases
Insert - Post
curl -H 'Content-Type: application/json' -X POST http://admin:password@127.0.0.1:5984/test -d '{"type": "user", "username": "jean", "application": "app1"}' curl -H 'Content-Type: application/json' -X POST http://admin:password@127.0.0.1:5984/test -d '{"type": "host", "hostname": "srv1", "application": "app1"}'
Select - Get
curl -d '{"keys":["73ab9c8c5dad9442ae91e6e1920088a5"]}' -H 'Content-Type: application/json' -X POST http://admin:password@127.0.0.1:5984/test/_all_docs?include_docs=true |jq . curl -d ' { "selector": { "username": "jean" }, "fields": [ "application" ] } ' -H 'Content-Type: application/json' -X POST http://admin:password@127.0.0.1:5984/test/_find |jq .docs curl -d ' { "selector": { "hostname": "srv1", "application": { "$in": ["app1","app2"] } }, "fields": [ "application" ] } ' -H 'Content-Type: application/json' -X POST http://admin:password@127.0.0.1:5984/test/_find |jq .docs curl -X PUT http://admin:password@127.0.0.1:5984/db/_design/my_ddoc -d '{"views":{"my_filter":{"map": "function(doc) { if(doc.date && doc.title) { emit(doc.date, doc.title); }}"}}}'
function(doc){ emit(doc.table.id, null); } { "views": { "all": { "map": "function(doc) { emit(doc.title, doc) }", } } }
Obsolète ?
pip install -U celery-with-couchdb pip install -U celery[couchdb]
https://couchdb-python.readthedocs.io/en/latest/getting-started.html https://readthedocs.org/projects/couchdb-python/downloads/pdf/latest/
https://pythonhosted.org/Flask-CouchDB/
pip install Flask-CouchDB
import couchdb couch = couchdb.Server('localhost:5984/') db = couch['newtweets'] count = 0 for docid in db.view('_all_docs'): i = docid['id']
Voir
pip install --upgrade "ibmcloudant>=0.0.42"
Source : https://blog.cloudant.com/2020/10/09/Automated-Daily-Backups.html
The couchbackup utility is a command-line tool that allows a Cloudant database to be turned a text file.
Turn our “animals” database into a text file
couchbackup --db animals > animals.txt
It comes with a matching utility which does the reverse: restores a text file back to a Cloudant database.
Restore our animals backup to a new database
cat animals.txt | couchrestore --db animals2
All we need to do is trigger couchbackup periodically to perform a backup.