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

Is there an ArangoDB-Object on Struct? #75

Closed
Fruchtgummi opened this issue Dec 18, 2017 · 3 comments
Closed

Is there an ArangoDB-Object on Struct? #75

Fruchtgummi opened this issue Dec 18, 2017 · 3 comments

Comments

@Fruchtgummi
Copy link

Fruchtgummi commented Dec 18, 2017

How do I get _key, _rev, _id and very important the lastkey (lastid) from Arango?

type mystruct struc {
   arangodb.document
  .....
or

  _key
  _lastkey
   ....
}

@ewoutp
Copy link
Contributor

ewoutp commented Dec 18, 2017

@Fruchtgummi all functions that modify a document return a DocumentMeta object.
That object contains the key, rev & ID field. No need to put that in your document structure (allthough you're allowed to do so)

See https://godoc.org/github.com/arangodb/go-driver#CollectionDocuments

@ewoutp ewoutp closed this as completed Dec 18, 2017
@ewoutp
Copy link
Contributor

ewoutp commented Dec 18, 2017

Humm. missed the lastkey part, checking...

@ewoutp ewoutp reopened this Dec 18, 2017
@ewoutp
Copy link
Contributor

ewoutp commented Dec 18, 2017

I've checked. When replacing or updating documents, there is also a _oldRev field. This field is not directly exposed in the go-driver API, but if can probably get it as follows:

The go driver has a WithReturnOld function that configures a context to return the old document after an update/replace operation.

type YourDocumentType struct {
    Rev string `json:"_rev"`
}
var oldDoc YourDocumentType
ctx := driver.WithReturnOld(context.Background(), &oldDoc)
_, err := collection.ReplaceDocument(ctx, key, newDocument)
if err == nil {
   // Now oldDoc.Rev contains the revision of the document before it was replaced

Hope that answers your question.

@ewoutp ewoutp closed this as completed Dec 18, 2017
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