Skip to content

nosql databases

For relational databases the choice is rather settled: postgres But for a nosql solution only one things was sure : NOT mongodb

Here is a list of possibilities for linux :

  • arangodb : distributed, contains documents,graphs and key values
  • CouchDB : distributed, free, easy REST interface
  • exist-db : XML based
  • mongodb : not free
  • redis : not free
  • rethinkdb : too old, stopped in 2016

For this list i think only arangodb deserves a second look. but couch-db is the best fit at this moment.

couchdb

CouchDB is a database that completely embraces the web. Store your data with JSON documents. Access your documents with your web browser, via HTTP. Query, combine, and transform your documents with JavaScript. (Apache)

  • debian package
  • free
  • supported

Note that couchdb uses (distributed) erlang, which is probably a think to investigate as well.

Couch db originates from apache, which is a good thing and it install without a single hiccup. You can directly query the database with curl or browse to http://localhost5984

curl http://localhost5984

Or you can use the ready to use fauxton interface on the same url with /\utils attached

visit

I would like to do it from my code, so here is a small guide.

note : i started with this tutorial, but that is obviously very old. visit

This one is at least more up to date, also note that tutorialspoint is not the best starting point ?

visit

There is also an own tutorial from couchdb :

visit

That last one might actually be the best one since it is the only one also mentioning you need to pass admin:password along with each curl command.

Using curl

Some options of curl I have not used before :

passing post data
curl -X POST http://mywebsite/ -D username=kees -D password=secret
save data to a file named download.txt
curl -O http://mywebsite/download.txt 
curl -o othername.txt http://mywebsite/download.txt 
getting only the headers
curl -I --http2 https://www.ubuntu.com/
output
HTTP/2 301 
server: nginx/1.14.0 (Ubuntu)
date: Sun, 18 Sep 2022 11:39:25 GMT
content-type: text/html
content-length: 175
location: https://ubuntu.com/
link: <https://assets.ubuntu.com>; rel=preconnect; crossorigin, <https://assets.ubuntu.com>; rel=preconnect, <https://res.cloudinary.com>; rel=preconnect
x-cache-status: HIT from content-cache-il3/2
follow all redirects
curl google.com
output
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>

But if you use -L it will continue any 301 until it has an answer

follow redirects until result
curl -L  google.com
sending along cookies
curl -L -b "oraclelicense=a" -O http://download.oracle.com/otn-pub/java/jdk/10.0.2+13/19aef61b38124481863b1413dce1855f/jdk-10.0.2_linux-x64_bin.rpm
sending along extra headers
curl https://reqbin.com/echo/get/json
   -H "X-Custom-Header: value"
   -H "Content-Type: application/json"

create database

You need to authenticate, so with curl you can do :

create database
curl -X PUT http://admin:password@127.0.0.1:5984/databasename

Of course my password is not that, and i will not repeat it every time.

output
{"ok":true}
list databases
curl -X GET http://admin:password@127.0.0.1:5984/_all_dbs
["_replicator","_users","databasename"]

A complete list of commands like this is here visit

What i like about couchdb is that you can guess how to delete the database very easy :

deleting again
curl -X DELETE http://admin:password@127.0.0.1:5984/databasename

map reduce

Here is a visual explanation of couchdb map reduce. : visit

You can see map - reduce as : perform an operation on all members of a collection(map) and return one value from that collection(reduce).