Couchbase on Nodejs - add() 方法是如何工作的?

Couchbase on Nodejs - how the add () method works?

这是一个基本问题,但我现在正在学习 couchbase,在我失败的情况下,我试图使用 add() 方法将数据插入到我的 couchbase 实例中。但是我的代码中有些东西不能正常工作,我不知道为什么。

var http = require("http");

var driver = require('couchbase');
var cb = new driver.Cluster("127.0.0.1:8091", null, null, "default");
var server = http.createServer(insertData);



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

server.listen(8080, insertData());

我 运行 服务器和控制台说它可以工作,但我的 CB 管理工具没有任何变化。

您似乎在 for 循环的开头有拼写错误:emps.lenght 应该是 emps.length

length 拼写错误。