Skip to content

couchdb: GetReplication (and other Replication methods) fail on clean CouchDB node #655

@iivvoo

Description

@iivvoo

With kivik/v4 and couchdb/v4

github.com/go-kivik/couchdb/v4 v4.0.0-20201202133216-34bafb9698c8

github.com/go-kivik/kivik/v4 v4.0.0-20201202093909-da42f0daa1b2

It seems the _replicator database has to be created explicitly (fauxton does this as well). Without it, GetReplications() will fail

package main

import (
	"context"
	"fmt"

	_ "github.com/go-kivik/couchdb/v4"
	"github.com/go-kivik/kivik/v4"
)

func main() {
	client, err := kivik.New("couch", "http://admin:a-secret@localhost:5984")
	if err != nil {
		panic(err)
	}

	existing, err := client.GetReplications(context.TODO())
	if err != nil {
		fmt.Printf("Failed to get replications: %v\n", err)

		if err := client.CreateDB(context.TODO(), "_replicator"); err != nil {
			panic(err)
		}
		existing, err = client.GetReplications(context.TODO())
		if err != nil {
			fmt.Println("Still doesn't work, giving up")
		}
	}
	fmt.Printf("Found %d replications\n", len(existing))
}

will print

# make sure it does not hold previous state, `docker rm` previous instances
» docker run -d -p 5984:5984 -e COUCHDB_USER=admin -e COUCHDB_PASSWORD=a-secret --name my-couchdb couchdb:3
» go run cmd/repl/main.go
Failed to get replications: Not Found: Database does not exist.
Found 0 replications

I'm not sure if this is something Kivik should deal with, but at least it might be worth mentioning

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions