Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use design documents with CouchDB.Net #184

Open
cfeltz34 opened this issue Mar 21, 2023 · 1 comment
Open

Use design documents with CouchDB.Net #184

cfeltz34 opened this issue Mar 21, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@cfeltz34
Copy link

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

@matteobortolazzo
Copy link
Owner

Hi, I didn't implement design documents in the library because they are Javascript functions. About the change feed, I suppose it contains design documents, too. The library doesn't know the type of object coming from the feed.

To create designs, you might want to try to use the Database's NewRequest method. That request is already scoped to a database and authenticated, you can add the missing paths with Flurl methods like AppendPath.

@matteobortolazzo matteobortolazzo added help wanted Extra attention is needed enhancement New feature or request and removed help wanted Extra attention is needed labels Jun 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants