Replacing a document with an updated json property

Hi All

I am trying to replace an existing documnet with an updated one and it is throwing an error ‘the output byte buffer is too small to contain the encoded data’

var bucket = await cluster.BucketAsync("");
var scope = await bucket.ScopeAsync("scopename");
var collection = await scope.CollectionAsync("collectionname");
var getResult = await collection.GetAsync("documentname");
var existingDoc = getResult.ContentAs<JObject>();
Console.WriteLine(existingDoc);

var currentCas = getResult.Cas;
Console.WriteLine($"Current Cas: {currentCas}");
                       

var replaceResult = await collection.ReplaceAsync(updatedJson, existingDoc, options => { options.Cas(currentCas); });

Please help and let me know if there anything wrong in here .
Thanks

Did you intend to have an empty string for the bucket name? Or was that just a redaction for this post?

It was just a redaction . It ahs valid values across.

My first guess would be something with a string longer than allowed, especially for the document key. Can you tell me how long all your various strings are if they’re unredacted?

1 Like

var replaceResult = await collection.ReplaceAsync(updatedJson, existingDoc, options => { options.Cas(currentCas); });

I’m thinking Brant is right. I’m looking at the above line of code as the likely culprit.

The first parameter of ReplaceAsync is id. You’re passing in updatedJson for the id. I don’t know what’s in updatedJson based on the code sample, but if it’s a JSON string, that likely isn’t what you meant to use for a id.

It worked … The issue was with the ID . Thanks

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.