2016-11-24 78 views
1

我的代码:我怎么能自动增量文档ID在对的NodeJS Couchbase

bucket.insert("docid", jsonVersion, function (err, response) { 
    if (err) { 
     console.log('Failed to save to Couchbase', err);  
     return; 
    } else { 
     res.send('Saved to Couchbase!'); 
    } 
}); 

我怎么能自动增加文件编号,当我从Web表单的数据。

我正在使用Nodejs和Couchbase。

+0

http://docs.couchbase.com/developer/java-2.1/documents-atomic.html – Hackerman

回答

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