Couchbase on Nodejs - add () 方法的工作原理

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

本文关键字:方法 工作 on Nodejs add Couchbase      更新时间:2023-09-26
这是一个

基本问题,但我现在正在学习 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的。

长度拼写错误。