List all indexes

Problem

Retrieve a list of all existing indexes within the current database.

Solution

Use the Indexes function combined with the Paginate function:

client.query(
  q.Paginate(q.Indexes())
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
{
  data: [
    Index("spells_by_element"),
    Index("spellbooks_by_owner"),
    Index("spells_by_spellbook"),
    Index("spells_by_element_and_name"),
    Index("elements_of_spells"),
    Index("letters"),
    Index("people_by_age_first"),
    Index("people_by_last_first"),
    Index("users_by_email"),
    Index("products_by_customer"),
    Index("products_by_store"),
    Index("inventory_by_product"),
    Index("products_by_price_high_to_low"),
    Index("products_by_price_low_to_high"),
    Index("all_customers"),
    Index("all_orders"),
    Index("all_products"),
    Index("all_stores"),
    Index("people_by_fullname"),
    Index("all_people"),
    Index("people_by_age_desc"),
    Index("people_by_first"),
    Index("people_by_first_last")
  ]
}
result = client.query(
  q.paginate(q.indexes())
)
print(result)
{'data': [Ref(id=spells_by_element, collection=Ref(id=indexes)), Ref(id=spellbooks_by_owner, collection=Ref(id=indexes)), Ref(id=spells_by_spellbook, collection=Ref(id=indexes)), Ref(id=spells_by_element_and_name, collection=Ref(id=indexes)), Ref(id=elements_of_spells, collection=Ref(id=indexes)), Ref(id=letters, collection=Ref(id=indexes)), Ref(id=people_by_age_first, collection=Ref(id=indexes)), Ref(id=people_by_last_first, collection=Ref(id=indexes)), Ref(id=users_by_email, collection=Ref(id=indexes)), Ref(id=products_by_customer, collection=Ref(id=indexes)), Ref(id=products_by_store, collection=Ref(id=indexes)), Ref(id=inventory_by_product, collection=Ref(id=indexes)), Ref(id=products_by_price_high_to_low, collection=Ref(id=indexes)), Ref(id=products_by_price_low_to_high, collection=Ref(id=indexes)), Ref(id=all_customers, collection=Ref(id=indexes)), Ref(id=all_orders, collection=Ref(id=indexes)), Ref(id=all_products, collection=Ref(id=indexes)), Ref(id=all_stores, collection=Ref(id=indexes)), Ref(id=people_by_fullname, collection=Ref(id=indexes)), Ref(id=all_people, collection=Ref(id=indexes)), Ref(id=people_by_age_desc, collection=Ref(id=indexes)), Ref(id=people_by_first, collection=Ref(id=indexes)), Ref(id=people_by_first_last, collection=Ref(id=indexes))]}
result, err := client.Query(
	f.Paginate(f.Indexes()))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
map[data:[{spells_by_element 0xc0000924b0 0xc0000924b0 <nil>} {spellbooks_by_owner 0xc0000925a0 0xc0000925a0 <nil>} {spells_by_spellbook 0xc000092690 0xc000092690 <nil>} {spells_by_element_and_name 0xc000092780 0xc000092780 <nil>} {elements_of_spells 0xc000092870 0xc000092870 <nil>} {letters 0xc000092960 0xc000092960 <nil>} {people_by_age_first 0xc000092a50 0xc000092a50 <nil>} {people_by_last_first 0xc000092b40 0xc000092b40 <nil>} {users_by_email 0xc000092c30 0xc000092c30 <nil>} {products_by_customer 0xc000092d20 0xc000092d20 <nil>} {products_by_store 0xc000092e10 0xc000092e10 <nil>} {inventory_by_product 0xc000092f00 0xc000092f00 <nil>} {products_by_price_high_to_low 0xc000092ff0 0xc000092ff0 <nil>} {products_by_price_low_to_high 0xc0000930e0 0xc0000930e0 <nil>} {all_customers 0xc0000931d0 0xc0000931d0 <nil>} {all_orders 0xc0000932c0 0xc0000932c0 <nil>} {all_products 0xc0000933b0 0xc0000933b0 <nil>} {all_stores 0xc0000934a0 0xc0000934a0 <nil>} {people_by_fullname 0xc000093590 0xc000093590 <nil>} {all_people 0xc000093680 0xc000093680 <nil>} {people_by_age_desc 0xc000093770 0xc000093770 <nil>} {people_by_first 0xc000093860 0xc000093860 <nil>} {people_by_first_last 0xc000093950 0xc000093950 <nil>}]]
try
{
    Value result = await client.Query(
        Paginate(Indexes())
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
ObjectV(data: Arr(RefV(id = "spells_by_element", collection = RefV(id = "indexes")), RefV(id = "spellbooks_by_owner", collection = RefV(id = "indexes")), RefV(id = "spells_by_spellbook", collection = RefV(id = "indexes")), RefV(id = "spells_by_element_and_name", collection = RefV(id = "indexes")), RefV(id = "elements_of_spells", collection = RefV(id = "indexes")), RefV(id = "letters", collection = RefV(id = "indexes")), RefV(id = "people_by_age_first", collection = RefV(id = "indexes")), RefV(id = "people_by_last_first", collection = RefV(id = "indexes")), RefV(id = "users_by_email", collection = RefV(id = "indexes")), RefV(id = "products_by_customer", collection = RefV(id = "indexes")), RefV(id = "products_by_store", collection = RefV(id = "indexes")), RefV(id = "inventory_by_product", collection = RefV(id = "indexes")), RefV(id = "products_by_price_high_to_low", collection = RefV(id = "indexes")), RefV(id = "products_by_price_low_to_high", collection = RefV(id = "indexes")), RefV(id = "all_customers", collection = RefV(id = "indexes")), RefV(id = "all_orders", collection = RefV(id = "indexes")), RefV(id = "all_products", collection = RefV(id = "indexes")), RefV(id = "all_stores", collection = RefV(id = "indexes")), RefV(id = "people_by_fullname", collection = RefV(id = "indexes")), RefV(id = "all_people", collection = RefV(id = "indexes")), RefV(id = "people_by_age_desc", collection = RefV(id = "indexes")), RefV(id = "people_by_first", collection = RefV(id = "indexes")), RefV(id = "people_by_first_last", collection = RefV(id = "indexes"))))
Paginate(Indexes())
{
  data: [
    Index("spells_by_element"),
    Index("spellbooks_by_owner"),
    Index("spells_by_spellbook"),
    Index("spells_by_element_and_name"),
    Index("elements_of_spells"),
    Index("letters"),
    Index("people_by_age_first"),
    Index("people_by_last_first"),
    Index("users_by_email"),
    Index("products_by_customer"),
    Index("products_by_store"),
    Index("inventory_by_product"),
    Index("products_by_price_high_to_low"),
    Index("products_by_price_low_to_high"),
    Index("all_customers"),
    Index("all_orders"),
    Index("all_products"),
    Index("all_stores"),
    Index("people_by_fullname"),
    Index("all_people"),
    Index("people_by_age_desc"),
    Index("people_by_first"),
    Index("people_by_first_last")
  ]
}
Query metrics:
  •    bytesIn:    29

  •   bytesOut: 1,757

  • computeOps:     1

  •    readOps:     8

  •   writeOps:     0

  •  readBytes: 1,174

  • writeBytes:     0

  •  queryTime: 199ms

  •    retries:     0

Discussion

The Paginate function defaults to returning up to 64 indexes per page. If your database contains more than 64 indexes, you can use the size parameter to retrieve up to 100,000 indexes at once.

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!