.Net Client (DP3) causing storage problems
I'm running couchbase-server-community_x86_64_2.0.0-1554-rel as a single server on OS X and reading & writing to it from .NET application using Couchbase-Net-Client-1.2-DP-3.
I initially wrote a series of JSON objects to the database. Using the browser console the objects displayed correctly, that is, all the objects were there and they displayed as structured JSON objects.
However, after deleting and rewriting a number of the objects from/to the database NONE of the database objects no longer appeared as JSON objects. Instead, each resembled a single stream of Base64 encoded characters.
Despite this, when the objects where read back into the .Net application the objects appeared as JSON objects and were successfully deserialized.
Since my colleague has been using Couchbase extensively via a Groovy interface without any problems at all I suspect the culprit is the .Net client.
So, is this a known problem and if so when may a fix available ?
Many thanks
Could you post the .NET code that was used?
I've dug a little deeper and found out exactly what the problem is ...
I'm attempting to write a complex object to Couchbase as a JSON string.
My object has several levels of embedded objects including collections of objects.
If I serialize the object (using Newtonsoft.Json) without any serialization settings then ...
... when the resulting JSON string is written it displays in the console correctly as a structured JSON object
... BUT when I read the string back it does not deserialize the string correctly
(in particular the embedded objects are not deserialized at all, they remain as JSON strings)
If I serialize / deserialize the object with the serialization settings ...
TypeNameHandling = TypeNameHandling.All
TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Full
... when the resulting JSON string is written it displays in the console as an attachment (it appears as
a binary string and thus can not be used for indexing)
... HOWEVER when I read the string back it does deserialize correctly
In short, the use of the serialize / deserialize settings seems to affect the manner in which Couchbase stores the data.
Code sample ...
POI poi = (POI)mnppObjectCreator.CreatePOIObject(nltKey);
// Generate a JSON object from the POI object
JsonSerializerSettings settings = new JsonSerializerSettings {
TypeNameHandling = TypeNameHandling.All, TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Full
};
string jsonInputObject = JsonConvert.SerializeObject(poi, settings);
// Write the JSON object to couchbase database
WriteToCouchbase(couchbaseClient, "POI:" + nltKey, jsonInputObject);
private void WriteToCouchbase(CouchbaseClient couchbaseClient, String key, Object jsonObject)
{
IStoreOperationResult result = couchbaseClient.ExecuteStore(StoreMode.Set, key, jsonObject);
if (!result.Success)
{
throw new TPException("EMPS150-1", "Could not write JSON object to CouchBase instance for key '" + key + "' ");
}
}
I shall be away from my desk for a couple of weeks but will be monitoring my email.
This bug is still present in the beta of the Couchbase .NET client 1.2.
Any chance of fixing this?
If Newtonsoft.Json is somehow producing a JSON string that Couchbase Server doesn't recognize as valid JSON, then the server creates the document as an attachment.
If someone has an example of an object graph that they could either attach to a new Jira issues (http://www.couchbase.com/issues) or to this post, I'll investigate. The client itself doesn't deal with JSON other than to send the string to the server.
This doesn't sound like a known problem, but given that we've fixed a number of issues recently and released both a beta of Couchbase Server 2.0 and a beta of the Couchbase .NET client 1.2, can you check that out?
Let me know if it's reproducible with those versions, and then we can dig in further if needed.