ContentAs<JObject> returns content with expiration

When the record is asked with expiration, than this value present inside content. Simple example.
Code:

var jObject = new JObject
{
    ["TestProp"] = "SomeValue"
};

var mutResult1 = await collection.InsertAsync(id1, jObject, insertOptions => insertOptions
    .Expiry(TimeSpan.FromMilliseconds(10000)));

var getResult1 = await collection.GetAsync(id1);
var value1 = getResult1.ContentAs<JObject>();
Console.WriteLine(value1.ToString(Formatting.Indented));

Console.WriteLine("--------------------------------------------");

var getResult2 = await collection.GetAsync(id1, getOptions => getOptions.Expiry());
var value2 = getResult2.ContentAs<JObject>();
Console.WriteLine(value2.ToString(Formatting.Indented));

Console:

{
  "TestProp": "SomeValue"
}
--------------------------------------------
{
  "$document": {
    "exptime": 1598520403
  },
  "": {
    "TestProp": "SomeValue"
  }
}

Hey @Ramirag,

What is the problem? What isn’t working as you expect?

Unexpected result.
For example the second getting throws exception. I think such behavior is wrong.

var mutResult1 = await collection.InsertAsync(id1, (int)5, insertOptions => insertOptions
    .Expiry(TimeSpan.FromMilliseconds(10000)));

var getResult1 = await collection.GetAsync(id1);
var value1 = getResult1.ContentAs<int>();
Console.WriteLine(value1);

Console.WriteLine("--------------------------------------------");

var getResult2 = await collection.GetAsync(id1, getOptions => getOptions.Expiry());
var value2 = getResult2.ContentAs<int>();
Console.WriteLine(value2);

5
--------------------------------------------
System.ArgumentException
System.ArgumentException: Can not convert Object to Int32.
   at Newtonsoft.Json.Linq.JToken.op_Explicit(JToken value)
   at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType)
   at Newtonsoft.Json.Linq.JToken.ToObject[T]()
   at Couchbase.KeyValue.GetResult.ContentAs[T]()
   at ConsoleApp1.CouchbaseTesting.Test() in C:\Users\Ivant\source\repos\ConsoleApp1\ConsoleApp1\CouchbaseTesting.cs:line 42

So, ContentAs<JObject> with expiry works as expected, but ContentAs<int> with expiry does not, is that correct?

Both doesn’t work as expected with expiry. And both work as expected without expiry. I want to get exactly the same I put to database. Not exception or with addition technical data.

@Ramirag agreed, that doesn’t look correct. Paging @jmorris for awareness.

@Ramirag -

Yes, this is a bug. I created a ticket and will get it into a release soon. There may be a work-around and will post one if found.

-Jeff

2 Likes