I have now seen several times, a problem with the latest 2.1.3 couchbase .net client failing silently on upsert, against a single node Couchbase 4 node.
I have my own Writer class which I wrote, which I create like this:
var writer = new CouchbaseExportWriter("http://hostname:8091/pools");
writer.openBucket("default");
The complete code of the class is shown here, including how I am invoking upsert:
On a COMPLETELY EMPTY default bucket, where NO DOCUMENTS YET EXIST, I get silent failures on my first upserts. I do 8000 upserts and a row, and they all quickly, silently fail. This is very troubling.
After I have created some documents in my empty single node cluster, in the default bucket, the C# client upsert method now succeeds.
What is going on?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Couchbase;
using Couchbase.Core;
using Couchbase.Configuration.Client;
using Couchbase.N1QL;
//using Couchbase.IO;
//using Couchbase.Management;
//using Couchbase.N1QL;
//using Couchbase.Views;
//using Couchbase.Utils;
using JsonDictionary = System.Collections.Generic.Dictionary<string, object>;
using JsonTableDictionary = System.Collections.Generic.Dictionary<string, System.Collections.Generic.Dictionary<string, object>>;
using JsonDictionaryItem = System.Collections.Generic.KeyValuePair<string, System.Collections.Generic.Dictionary<string, object>>;
namespace FirebirdTest1
{
class CouchbaseExportWriter
{
private ClientConfiguration _config;
private Cluster _cluster;
private IBucket _bucket;
public ClientConfiguration config { get; set; }
public Cluster cluster { get; set; }
public IBucket bucket { get; set; }
// serverurl = "http://hostname:8091/pools"
public CouchbaseExportWriter( string serverUrl)
{
_config = new ClientConfiguration();
_config.Servers.Add(new Uri(serverUrl));
_cluster = new Cluster(_config);
}
public int getBucketItemCount()
{
if (_bucket != null)
{
string qryText = "SELECT COUNT(*) FROM `" + _bucket.Name + "`";
var queryRequest = new QueryRequest(qryText);
var result = _bucket.Query<dynamic>(queryRequest);
var row = result.Rows[0];
return row["$1"]; // Get value for default $1 result
}
else
{
return 0;
}
}
public void openBucket(string bucketName)
{
_bucket = _cluster.OpenBucket(bucketName);
}
public void upsert( Couchbase.Document<dynamic> document)
{
_bucket.Upsert(document);
}
public void upsert(string id, JsonDictionary documentDictionary )
{
var couchDoc = new Couchbase.Document<dynamic>
{ Id = id,
Content = documentDictionary
};
_bucket.Upsert(couchDoc);
}
public void delete(string id)
{
bucket.Remove(id);
}
}
}