So I got round to making an example illustrating my issue. The two set 
methods (one commented out) I would expect to behave identically, but using 
"copiedCas" fails with [Error: Bad CAS] code: 4098 (or with 
keyAlreadyExists if you use the Mock server).




var should = require("should");
var couchbase = require('couchbase');
var connection = new couchbase.Connection({ host: 'localhost:8091', bucket: 
'unit_tests' });
//var connection = new couchbase.Mock.Connection();

describe('issue with copying cas', function() {
it('should succeed', function(done){
var testObj = { foo: "bar" };
connection.set('test', testObj, function(err, result) { // Insert with no 
cas option i.e. overwrite any existing data
should.not.exist(err);
connection.get('test', function(err, result) { // Retrieve the just added 
document
should.not.exist(err);
should.exist(result.cas);
should.exist(result.value);
result.value.foo = "bar2";
var copiedCas = JSON.parse(JSON.stringify(result.cas));
copiedCas.should.be.eql(result.cas); // The two cas values are equal
connection.set('test', result.value, { cas : copiedCas }, function(err, 
result) { // Doing it this way fails
// connection.set('test', result.value, { cas : result.cas }, function(err, 
result) { // Doing it this way succedes
should.not.exist(err);
should.exist(result);
done();
});
});
});
});
});

-- 
You received this message because you are subscribed to the Google Groups 
"Couchbase" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to