Creating a product catalog with djondb, PHP Restler and Backbone JS Part II – Setting up


In our previous post, we have explained some aspects of the application we are building with djondb. In this post, we’ll install djondb, the enterprise class NoSQL database and we’ll play around a little bit with the console.

Installing djondb

First of all, download and install djondb. You can get the djondb installer from djondb downloads page: In this example we will use the OSX version. Just open the OSX package and follow the instructions of the installer.

The installer does not create the database folder, so you will need to do this manually, just run the following command in a terminal window:

sudo mkdir /var/djondb
sudo chown ‘id -u’ /var/djondb

Sudo allows you to execute admin tasks in your machine, so you can create the folder in the protected area “var”, which is normally used to store the files used by OSX applications.

Once you have the folder create you can run djondb server. Using the terminal type:

djondbd -n
INFO:7fff7b008310: djondbd version 3.5.60107 is starting up.
INFO:7fff7b008310: DBController initializing. Data dir: /var/djondb/
INFO:1042f0000: djondb server ready. Port: 1243
INFO:104373000: web interface ready. Port: 8090. Web Folder: /var/webconsole

Congratulations, you have djondb running and ready to server your application, the -n allows you to run the server in interactive mode, please don’t close this console session or it will shutdown the database. For any other new terminar related elements open a new session of the terminal.

Using the console

Now let’s give it a try, open another terminal window and launch the djondb-shell:

djondb shell version 3.5.60107
Welcome to djondb shell.
Use help(); to get the commands available. 
(hint: The first command should be "connect" to start playing with a server)

Let’s connect to localhost:

> connect('localhost');
Connected to localhost

Let’s insert some data (please copy and paste the text of the following sample as we will use this product later in our application):

insert('demodb', 'products', {"_id": "1", "prodtype": "book", "name": "NoSQL Distilled", "picture": "nosql.jpg", "author": "Martin Fowler", "price": "29.29", "releasedate": "2012/08/08", "isbn": "0321826620"});

We inserted a product in products namespace in the demodb database. May be you have noticed that you don’t have to create the database or namespaces, djondb creates them on the fly if they don’t exist.

Now, let’s retrieve the data we’ve just inserted:

> var c = find ('demodb', 'products', "name == 'NoSQL Distilled'");
> c.current()
[{"_id":"1","_revision":"0508ADCE-500D-4BB4-96AD-69FEBBAAE479","_status":1,"author":"Martin Fowler","isbn":"0321826620","name":"NoSQL Distilled","picture":"nosql.jpg","price":"29.29","prodtype":"book","releasedate":"2012/08/08"}]

The find method returns a cursor to your data, so you can iterate over your data using “.next()” and retrieve the current element using .current(), you can also use the web console to execute DQL commands, just open your browser (Safari, Chrome, even IE!!) and type the address: http://localhost:8090 it will open the web console where you can execute DQL commands as explained here: Usually this console will be disabled in production environments so let’s keep using the shell in our example.

The example above retrieved a product from products namespace in demodb database where its name is equals to NoSQL Distilled cialis aus holland.

Now we have the database ready and we will prepare the rest of our environment to jump to the coding phase. In next part, we’ll create the services layer of our application using PHP, see you then.

Posted in djondb application, NoSQL Samples and tagged .
Loading Facebook Comments ...

Leave a Reply

Your email address will not be published. Required fields are marked *