【问题标题】:Couchbase on Nodejs - how the add () method works?Couchbase on Nodejs - add() 方法如何工作?
【发布时间】:2015-01-28 13:43:51
【问题描述】:

这是一个基本问题,但我现在正在学习 couchbase,但在失败中,我尝试使用 add() 方法将 Data 插入到我的 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 Admin 工具没有任何变化。

【问题讨论】:

标签: javascript node.js couchbase nosql


【解决方案1】:

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

length 拼写错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-16
    • 2020-01-23
    • 2015-12-12
    • 1970-01-01
    • 2018-02-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多