我的代码:
bucket.insert("docid", jsonVersion, function (err, response) {
if (err) {
console.log('Failed to save to Couchbase', err);
return;
} else {
res.send('Saved to Couchbase!');
}
});
当我从网络表单获取数据时,如何自动增加文档ID。
我正在使用Nodejs和Couchbase。
答案 0 :(得分:1)
你在Couchbase中没有AutoIncrement。 你所拥有的是Counters。 使用计数器,您可以在原子问题中递增一个数字,然后将其分配或连接到您的docId。
类似的东西:
bucket.counter(counterKey, 1, {initial: 0}, function(err, res) {
if (err) throw err;
// insert code here
console.log('Incremented Counter:', res.value);
console.log('Example Successful - Exiting');
process.exit(0);
});
更多示例请看这里: https://github.com/couchbaselabs/devguide-examples/tree/master/nodejs