Why i get this error?


#1

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

console.log (“BA4KAAAAA!!”);

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);
        }
    });
}

}
baseview.setDesign(‘design_employees’, {
‘basic_list’: {
‘map’: “function (doc, meta) { if(doc.type == ‘employee’) {emit(meta.id, doc.name);}}”
}
}, function(err, res) {
if (err != null) console.log(err); });

server.listen(8080, insertData());

This is my code and when i run it it says : “typeError undefined is not a function”


#2

Hey lfc321,

I believe the reason for the issue is that you are using .setDesign, with the 2.x series of SDK, the method you want to use would be insertDesignDocument (though you are using some kind of wrapper which may make me wrong).

Cheers, Brett


#3

I think the problem is somewhere here var cb = new driver.Couchbase("127.0.0.1:8091","default"); but i’m not sure