Details
Description
When you try to execute this code the application crashes:
var async = require("async");
var couchBase = require("couchbase");
var json = {
"id1": {
"id": "id1",
"name": "Name 1"
},
"id2": {
"id": "id2",
"name": "Name 2"
}
};
var config = {
"host": "localhost",
"port": 8091,
"username": "Administrator",
"password": "password",
"bucket": "requests"
};
couchBase.connect(config, function(err, bucket) {
if (err) {
console.log("Unable to connect to Couchbase bucket [" + config.bucket + "]", err);
process.exit(1);
}
console.log("Connected to Couchbase");
var ids = [];
var jsonDocs = [];
for (var key in json) {
if (json.hasOwnProperty(key)) {
var jsonDoc = json[key];
var id = jsonDoc.id;
jsonDocs.push(jsonDoc);
ids.push(id);
}
}
bucket.get(ids, null, function(err, docs, metas) {
if (err) {
for (var j = 0; j < err.length; j++) {
if (err[j].code != 13) {
console.log({ err: err }, "Unable to get existing entries using multiple get. Error in element [" + j + "]");
process.exit(1);
}
}
}
console.log("Checked all docs for existance");
async.map(jsonDocs, function(doc, callback) {
bucket.set(doc.id, doc, {}, function(err) {
callback(err);
});
}, function(err, results) {
if (err) {
console.log("Unable to save all entries", err);
process.exit(1);
}
console.log("Saved all entries");
process.exit(0);
});
});
});
The question comes originally from:
http://stackoverflow.com/questions/14829946/couchbase-2-0-on-node-js-crashes-when-using-multiple-get
http://www.couchbase.com/forums/thread/couchbase-2-0-node-js-crash-mac-os-x-mountain-lion