Posted 07 February 2013 - 03:48 AM

Stores data in JSON document

Very fast in action

This is not a relational database, so no need of database normalization

There is no limit of creating documents under a database

Npm install felix-couchdb

Press the 'New Document' button and the document test page is ready with a field name _id, this is the name of our document

Change the value of the _id as 'testdocument'

On the right side click on the green tick, this will temporarily save the document

To add new field click add field button and name the field as 'testfield' and set a value for the field testfield

Finally click the Save Document button on the top

After successfully document creation we can see our document

//server.js var couchdb = require('felix-couchdb'), //if username: root password : root this will be ..createClient(5984, 'localhost','root','root'); client = couchdb.createClient(5984, 'localhost',), db = client.db('newtestdatabase'); db.create(function(error){ if (error) throw new Error(JSON.stringify(error)); console.log('Created new db. with name '+JSON.stringify(db.name)); });

db.saveDoc('newtestdocument', {"newtestfield" : "newtestfieldvalue"}, function(error, ok) { if (error) throw new Error(JSON.stringify(error)); console.log('Saved my first doc to the couch! operation info: '+JSON.stringify(ok)); });

Attached Files node3_felix-couchdb.zip 27.91KB 352 downloads

In the last tutorial we had come with the basics of a http server. There we implemented a simple http server that can respond as the client requests. The http server was able to serve each of the requested files. Today we will start learning about CouchDB database. We will learn how to install CouchDB, how to install external node modules, the basic operations of CouchDB etc.Check out our other node.js content CouchDB is a database introduced by Apache and its one of the NoSQL types. Its JSON based, there is no relational system in CouchDB that means its not a relational database management system as we see MYSQL. It only stores data in JSON file. The table concept can be replaced here by document (The JSON data file) but no relation between the documents.Download CouchDB from here . Install it and run the database by the starting the “Start CouchDb” program. CouchDB comes with a built-in admin interface called Futon. We can see the interface on http://localhost:5984/_utils/ . There we can create database, documents and can do all other operations in a graphical way. This interface should look like thisSee there is a create database button on top left corner. We will use this to create a new database.Node.js lives with node modules. There are lots of internal and external modules for different purpose. Simply node modules are function libraries are exported for use with various application. For interaction with CouchDB there a good module namedfelix-couchdb. Felix-couchdb module is made for interaction between node application and CouchDB. Installing felix-couchdb is easy. Run the command in the node command promptNpm is Node package manager, it comes with node distribution. It handles everything about node modules like installing, updating modules type operations. After running the command in node CLI the felix-couchdb module is installed and ready to work with our node application.Creating database in CouchDB is easy. Use the 'create database' button on the top left corner in the CouchDB interface to create a database. For example 'testdatabase'. After successfully database creation we can see the internal window of the 'testdatabase'.Now we will create a new document in the 'testdatabase' database. For example we will create the document named 'testdocument'.Notice that an extra field name _rev is automatically created, notice that the value of the field, it describes the revision number with the unique id number separated by a - hyphen mark and its very sensitive, so don't change the _rev value. We can edit the document any time by just double click on the value.To delete the document there is a button 'Delete Document', simply use this to delete a document.We can use this module by simply require(‘felix-couchdb’). Then we need to create a client to get interacted with our app with CouchDB. We can use password for some specific username , here is a way default way to connecting with CouchDB from Node.js application.Run this on the CLI, if the database is created then the message will come with the database name. If any error occurred node will show the error message. So our first database is created. Now we will create a document in the newly created database.

Edited by Roger, 19 February 2013 - 02:43 PM.

added links