Closed
Description
Hi! I continue using CouchDB.NET and while it gives us a lot of convenient features I have found one thing to be discussed. It looks like a minor bug. But you have the last word on that.
The issue is described below:
var docIdList = new List<string> {
"entity:123456", // doc with such id is present in CouchDB
"entity:987654" // doc with such id is NOT present in CouchDB
};
var entityList = await _context.Entities.FindManyAsync(docIdList);
In this case the response from CouchDB will be the following:
{
"results": [
{
"id": "entity:123456",
"docs": [
{
"ok": {
"_id": "entity:123456",
"_rev": "1-d0fd0ab0ea6df92644423c6dfcf53174",
...
}
}
]
},
{
"id": "entity:987654",
"docs": [
{
"error": {
"id": "entity:987654",
"error": "not_found",
"reason": "missing"
}
}
]
}
]
}
And entityList will have two items: fetched entity with id 123456 and null for not found entity with id 987654.
My point is that we do not want this null to be present in the resulted list.
If so I can make a PR like this:
public async Task<List<TSource>> FindManyAsync(...)
{
BulkGetResult<TSource> bulkGetResult = await NewRequest()
.AppendPathSegment("_bulk_get")
.PostJsonAsync(new
{
docs = docIds.Select(id => new { id })
}, cancellationToken)
.ReceiveJson<BulkGetResult<TSource>>()
.SendRequestAsync()
.ConfigureAwait(false);
var documents = bulkGetResult.Results
.SelectMany(r => r.Docs)
.Select(d => d.Item)
.Where(i => i != null) // <== filter only existing documents
.ToList();