Something wrong into my Add() method


var http = require(“http”);
var server = http.createServer(insertData);
var driver = require(‘couchbase’);
var cb = new driver.Cluster(“localhost:8091”,“default”);
var baseview = require(‘baseview’)({url: ‘’, bucket:‘default’});

console.log (“bachka si”);

function insertData() {
var emps = [{
“type”: “employee”,
“id”: 100,
“name”: “Anton”,
“dept”: “Sales”,
“salary”: 5000
}, {
“type”: “employee”,
“id”: 200,
“name”: “Ivan”,
“dept”: “IT”,
“salary”: 3000
}, {
“type”: “employee”,
“id”: 300,
“name”: “Petko”,
“dept”: “Manager”,
“salary”: 10000

for (index = 0; index < emps.lenght; index++) {
    cb.add(JSON.stringify(emps[index].id), JSON.stringify(emps[index]), 0, undefined, function (data, err, key, cas) {
        if (err && err != 12) {
            console.log("FAIL!" + err);

Here i try to insert data into my Couchbase instance. Everything works fine says the console and there is no error there but when i open my Couchbase Admin Console there is no new Data. And i cant understand why ?


Hey lfc321,

Your line for (index = 0; index < emps.lenght; index++)
uses emps.lenght (undefined == 0)
rather than emps.length (3).

Cheers, Brett


So it becomes 0<0 but can u explain me why ? I’m totaly new in couchbase. I will tell you if your sugestion works tommorow


Hey lfc321,

To check the length of an array in Javascript, you need to use ARRAY.length, you’ve typo’d and used .lenght instead, which will evaluate to undefined as there is no such property for an array.

Cheers, Brett