Phylosophy behind the drivers

All of the djondb drivers works over the same base driver, that has two main purposes, the first one is to ensure that all the drivers has exactly the same features, the second is to ensure that drivers works the same way and they have the same documentation (almost).

Using the driver

The installation of the driver is a two step process, first you will need the djondb development files, if you installed the server, and you're going to use the nodejs driver on the same machine, then you won't need the development package.

The development files can be found at

  • Downloads
  • With the development files installed you are ready to install the djondb module using:

    npm install djondb

    Hello Peter!

    Now let's write the typical "Hello world!" sample:

    var addon = require('djondb');
    
    var manager = new addon.WrapConnectionManager();
    var con = manager.getConnection("localhost");
    con.open();
    
    var hero = { name: 'Peter', lastName: 'Parker', occupations: [ { company: 'Daily Bugle', position: 'Photographer'}, { position: 'Superhero' } ], nicknames: [{ name: 'Spiderman', main: 1}, {'name': 'Spidey'}] };
    
    con.insert("test_nodejs", "superheroes", hero);
    
    var res = con.find("test_nodejs", "superheroes", "$'name' == 'Peter'");
    
    for  (var x = 0; x < res.length; x++) {
       var bhero = res[x];
       console.log("Hero name: " + bhero["name"]);
    }
    
    manager.releaseConnection(con);

    The first step should be the reference to the module:

    var addon = require('djondb');

    Now that we have our djondb library loaded, we could adquire a connection though the WrapConnectionManager, and open it, using:

    var manager = new addon.WrapConnectionManager();
    var con = manager.getConnection("localhost");
    con.open();

    Getting the connection is very simple, just use the WrapConnectionManager to get a new connection from the pool and ensure it is open using the "open" method. Note: It's always a wise move to check if the open method returned true, this means the connection was established with the server.

    Once you finish your operations you should release your connection using the method "releaseConnection" from the WrapConnectionManager.

    The next instruction is simple, you insert a new JSON Document (a javascript object) using the insert method, the first argument is the database and the second is the namespace where you want to store this new document:

    con.insert(<database>, <namespace>, <JSON Document>);

    Now that we stored the document we could get it back from the server using the find method, which works exactly as it's explained in the user guide:

    var res = c.find("test_nodejs", "superheroes", "$'name' == 'Peter'");
    
    var res = con.find(<database>, <namespace>, <filter>);

    the Nodejs driver will return a plain javascript object so you will be able to use the returned array as any other javascript variable.