Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Couchbase lite document entries converted to generic list from Dictionary on document update

EmanBuhagiarEmanBuhagiar MTMember
edited November 2016 in Xamarin.Forms

In my Xamarin Forms app I'm creating a database and 2 documents using Couchbase lite. After creating these 2 documents and putting properties into them from the server, there's no problem in reading that data by using:

var database = Manager.SharedInstance.GetDatabase("indigodb");
var retrievedDocument = database.GetExistingDocument("user");

List<string> companiesList = new List<string>();
IDictionary<string, object> contents = retrievedDocument.Properties;

foreach (KeyValuePair<string, object> entry in contents)
{
      if (entry.Key == "Companies" && entry.Value != null)
       foreach (string item in (entry.Value as JArray).ToObject<string[]>())
                    companiesList.Add(item);
}

entry.Value is stored as a JArray when putting the properties at earlier stage.

The problem arises when it comes to updating the document using:

var userDocument = database.GetExistingDocument("user"); SavedRevision newVersion = userDocument.Update(rev => { var propertiesUser = rev.UserProperties; propertiesUser["Code"] = Globals.User.ApplicantCode; propertiesUser["FirstName"] = Globals.User.FirstName; propertiesUser["LastName"] = Globals.User.LastName; rev.SetUserProperties(propertiesUser); return true; });
where Globals.User.ApplicantCode, FirstName and LastName are strings.

When I'm trying to go through the properties data again using the first code above, entry.Value now becomes of type generic list and not as JArray anymore so that throws an exception.

I'm trying to see what I'm doing wrong in reading the document properties data or in updating the document (or both), as I cannot seem to find any help online. I hope you understand the issue well.

Thanks! :)

Tagged:
Sign In or Register to comment.