couchdb-net
couchdb-net copied to clipboard
Resolve conflicts
I didn't understand how to work with conflicts. I need to find, apply resolution logic, and remove any conflicts.
According to the couchdb specification the command to send would be this:
GET /recipes/SpaghettiWithMeatballs?rev=6-136813b440a00a24834f5cb1ddf5b1f1
I haven't found how to do this with your library. Thank you
I tried adding this method to the CouchDatabase class of your library and it works. Could it be interesting to add it to the standard version?
public async Task<TSource?> FindAsync(string docId, string rev, bool withConflicts = false,
CancellationToken cancellationToken = default)
{
IFlurlRequest request = NewRequest()
.AppendPathSegment(docId);
if (rev?.Length > 0)
{
request = request.SetQueryParam("rev", rev);
}
if (withConflicts)
{
request = request.SetQueryParam("conflicts", "true");
}
IFlurlResponse? response = await request
.AllowHttpStatus(HttpStatusCode.NotFound)
.GetAsync(cancellationToken)
.ConfigureAwait(false);
return response != null && response.StatusCode == (int)HttpStatusCode.OK
? await response.GetJsonAsync<TSource>().ConfigureAwait(false)
: null;
}
Hi, sorry for the late answer,
I checked the docs, they say to merge them manually, upload the new version and then delete the conflicted one to resolve. https://docs.couchdb.org/en/stable/replication/conflicts.html#working-with-conflicting-documents
So I can give a look at how to implement this correctly as both the get and the delete need a rev parameter
But the merge itself must be done manually so not sure how useful it would be to add the rev to the library
Hello!
Because not only @mauro-rogledi need passing revision to FindAsync
, but also I need to pass revision to AddOrUpdateAsync
method, I made the pull request covering both cases.
I suggest not to add parameters, but introduced parameter object for both methods in my pull request.
@dmlarionov PR is now merged in dev, sorry for the delay. Will release soon