Database

This feature is not available if you are using the built js version

For a faster development, we offer a NoSQL solution that requires no configuration. We recommend to use redis, mongoose or rethinkdb when your app is production-ready.

Contents

Configuration

Change the path of your NoSQL with client.nosql.path().

client.nosql.path("./data");

Get

Retrieve by cid.

Parameters:

  • collection: String
  • cid: Integer
client.nosql.get("monsters", 3).then(function(data) {
    console.log(data);
});

Insert

Insert, add or push a list of elements.

Parameters:

  • collection: String
  • elements: Array or Object
client.nosql.insert("monsters", [
    {name: "sphinx", mythology: "greek", eyes: 2, sex: "f", hobbies: ["riddles","sitting","being a wonder"]},
    {name: "hydra", mythology: "greek", eyes: 18, sex: "m", hobbies: ["coiling","terrorizing","growing"]},
    {name: "huldra", mythology: "norse", eyes: 2, sex: "f", hobbies: ["luring","terrorizing"]},
    {name: "cyclops", mythology: "greek", eyes: 1, sex: "m", hobbies: ["staring","terrorizing"]},
    {name: "fenrir", mythology: "norse", eyes: 2, sex: "m", hobbies: ["growing","god-killing"]},
    {name: "medusa",  mythology: "greek", eyes: 2, sex: "f", hobbies: ["coiling","staring"]}
]).then(function() {
    console.log("Inserted data.");
});
client.nosql.insert("monsters", {name: "HamoIzm", mythology: "amazigh", eyes: 2, sex: "m", hobbies: ["riddles","hunting"]}).then(function() {
    console.log("Inserted data.");
});

List

List all elements in the collection.

Parameters:

  • collection: String
client.nosql.list("monsters").then(function(result) {
    console.log(result);
});

Remove

Delete an item by cid.

Parameters:

  • collection: String
  • cid: Integer
client.nosql.remove("monsters", 1).then(function() {
    console.log("Removed cid 1.");
});

Replace

Replace the element with the same cid.

Parameters:

  • collection: String
  • cid: Integer
  • elements: Array or Object
client.nosql.replace("monsters", 6, {car: "Ferrari"}).then(function() {
    console.log("Replaced cid 6..");
    client.nosql.get("monsters", 6).then(function(result) {
        console.log(result);
    });
});

Update

Update an element, it will add un-existed key and replace existed. ($created and cid can't be changed)

Parameters:

  • collection: String
  • cid: Integer
  • elements: Array or Object
client.nosql.update("monsters", 5, {eyes: 3, food:"waloo"}).then(function() {
    console.log("Updated cid 5..");
    client.nosql.get("monsters", 5).then(function(result) {
        console.log(result);
    });
});

Where

Search using an object or operators.

Parameters:

  • collection: String
  • elements: Array or Object
client.nosql.where("monsters", {name: "sphinx"}).then(function(result) {
    console.log(result);
});
client.nosql.where("monsters", "@eyes >= 2").then(function(result) {
    console.log(result);
});
client.nosql.where("monsters", "(@eyes == 2 && @mythology == 'greek') || (@mythology == 'amazing')").then(function(result) {
    console.log(result);
});