{{tag>Brouillon NoSQL JSON}} = Notes CouchDB Voir aussi : * MongoDB * ArangoDB * RethinkDB * https://fr.m.wikipedia.org/wiki/Riak * https://couchapp.readthedocs.io/en/latest/intro/what-is-couchapp.html Voir : * https://guide.couchdb.org/editions/1/fr/tour.html * https://jo.github.io/couchdb-best-practices/ * https://docs.couchdb.org/en/stable/best-practices/index.html * https://link.springer.com/content/pdf/bbm%3A978-1-4302-7236-6%2F1.pdf * https://couchdb.developpez.com/tutoriels/guide-authentique/introduction/ * https://laethy.developpez.com/tutoriels/couchdb/guide-authentique/ * https://www.mongodb.com/compare/couchdb-vs-mongodb * https://www.tutorialspoint.com/couchdb/couchdb_quick_guide.htm * https://fr.acervolima.com/introduction-a-apache-couchdb/ * https://guide.couchdb.org/editions/1/es/documents.html * https://www.oreilly.com/live-events/couchdb-first-steps/0636920473183/0636920473176/ * https://docs.couchdb.org/en/stable/best-practices/index.html * https://guide.couchdb.org/draft/documents.html * http://www.gschnabel.com/storage/presentations/20200513_WPEC_SG49_EXFOR_CouchDB_database_Georg_Schnabel.pdf Code : * https://couchdb-python.readthedocs.io/en/latest/mapping.html docker run -d --name my-couchdb -p 5984:5984 -e COUCHDB_USER=admin -e COUCHDB_PASSWORD=password couchdb:3.2.1 WebUI Fauxton Futon * http://127.0.0.1:5984/_utils/ 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://cran.r-project.org/web/packages/sofa/vignettes/query_tutorial.html 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 * https://www.oreilly.com/library/view/couchdb-the-definitive/9780596158156/ch03.html * https://www.oreilly.com/library/view/couchdb-the-definitive/9780596158156/ch04.html 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) }", } } } == Programmation - db drivers 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 * cloudant * cloudant-python-sdk pip install --upgrade "ibmcloudant>=0.0.42" == Outils tiers === CouchBackup 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.