Get an index document

Problem

You need to retrieve the document that describes an index from the current database.

Solution

Use the Get function:

result, err := client.Query(
	f.Get(f.Index("all_people")))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
map[active:true name:all_people partitions:8 ref:{all_people 0xc0000924b0 0xc0000924b0 <nil>} serialized:true source:{People 0xc0000925a0 0xc0000925a0 <nil>} ts:1631912050530000 values:[map[field:[data first]] map[field:[data last]] map[field:[ref]]]]
client.query(
  q.Get(q.Index('all_people'))
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
{
  ref: Index("all_people"),
  ts: 1631909326360000,
  active: true,
  serialized: true,
  name: 'all_people',
  source: Collection("People"),
  values: [
    { field: [ 'data', 'first' ] },
    { field: [ 'data', 'last' ] },
    { field: [ 'ref' ] }
  ],
  partitions: 8
}
result = client.query(
  q.get(q.index("all_people"))
)
print(result)
{'ref': Ref(id=all_people, collection=Ref(id=indexes)), 'ts': 1631911190460000, 'active': True, 'serialized': True, 'name': 'all_people', 'source': Ref(id=People, collection=Ref(id=collections)), 'values': [{'field': ['data', 'first']}, {'field': ['data', 'last']}, {'field': ['ref']}], 'partitions': 8}
Get(Index("all_people"))
{
  ref: Index("all_people"),
  ts: 1631835750270000,
  active: true,
  serialized: true,
  name: 'all_people',
  source: Collection("People"),
  values: [
    { field: [ 'data', 'first' ] },
    { field: [ 'data', 'last' ] },
    { field: [ 'ref' ] }
  ],
  partitions: 8
}
Query metrics:
  •    bytesIn:   30

  •   bytesOut:  336

  • computeOps:    1

  •    readOps:    1

  •   writeOps:    0

  •  readBytes:  169

  • writeBytes:    0

  •  queryTime: 88ms

  •    retries:    0

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!