Open
Description
I have create a CouchDB database with a CouchContext :
public class CouchDBContext : CouchContext
{
public CouchDatabase<ExampleDataCouchDB> ExampleDatas { get; set; }
public CouchDBContext(CouchOptions<CouchDBContext> options)
: base(options)
{
}
}
With couchDB web interface I created the following design :
{
"_id": "_design/example",
"filters": {
"updateonly": "function(doc, req) { if (doc.status != 'new') { return true; } return false; }",
"maxid": "function(doc, req) { if (parseInt(doc.Id) < 1050) { return true; } return false; }"
},
"language": "javascript"
}
Remark : I couldn't find any documentation to create the design from CouchDB.Net. It's possible ?
I also created a listener to detect changes on this database :
await foreach (var change in _couchDBContext.ExampleDatas.GetContinuousChangesAsync(
options: new ChangesFeedOptions {
IncludeDocs=true,
Style = ChangesFeedStyle.MainOnly,
Filter = (String.IsNullOrEmpty(data.filter)?null:data.filter)
},
filter: null, cancellationToken.Token))
{
_logger.LogInformation($"New change on CouchDB: {change.Id} - {change.Changes[0].Rev} ({change.Changes.Count})");
if (change.Document.Id.StartsWith("_design"))
{
// ??? --> why couchDBContext.ExampleDatas.GetContinuousChangesAsync have the design documents ?
}
}
_couchDBContext.ExampleDatas.GetContinuousChangesAsync return ExampleDataCouchDB objects but my "_design/example" is not a ExampleDataCouchDB object.
I don't understand what is the best practice to use the design documents with CouchDB.Net.
Can you help me and may be improve the documentation ?
You don't explain how to add it by code.
See https://docs.couchdb.org/en/stable/ddocs/ddocs.html#creation-and-structure