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

Get(doc CouchDoc, id string) didn't seem to return the couchdb document revision #13

Closed
steffenrost opened this issue Apr 12, 2017 · 3 comments

Comments

@steffenrost
Copy link

Hi Mirco,
when I retrieve a document using the Get() method in database.go the revision information didn't seem to be set. I use GetRev() on the returned document but it just returns an empty string. Because of this a subsequent Put call using the same document (with an empty revision) fails with a document update conflict. Do I miss here something, can you perhaps provide an example for this use case?

Thanks in advance.

@steffenrost steffenrost changed the title Get(doc CouchDoc, id string) didn't seem to return use the couchdb document revision Get(doc CouchDoc, id string) didn't seem to return the couchdb document revision Apr 12, 2017
@zemirco
Copy link
Owner

zemirco commented Apr 12, 2017

Can you show me some code?

@steffenrost
Copy link
Author

Sure, last thing I tried was to explicitly set id/rev before doing the get and then do a subsequent put call which also returns me an update conflict error ... GetRev() and GetId() only returns a valid rev/id when I set both fields in DummyDocument explicitly.

type DummyDocument struct {
couchdb.Document
lib.Environment
}
...
doc := &DummyDocument{

	Document: couchdb.Document{
		ID:  "1d89d942a9635eb22142fcd8385bc8d3",
		Rev: "1-2f7940356a6c9e852f73409a40f0e47c",
	},

	Environment: lib.Environment{},
}

...
err = db.Get(doc, "1d89d942a9635eb22142fcd8385bc8d3")
t.Logf(" ... reading environment record with id: %v and rev: %v succeeded ...", doc.GetID(), doc.GetRev())
..
resp, err := db.Put(doc)

@steffenrost
Copy link
Author

I found meanwhile what was causing the issue, problem was that I embedded the document containing id/rev into a document also defining these two fields. Sorry for the 'flurry', will close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants