Delete an index

Problem

You need to delete an index from the current database.

Solution

Use the Delete function:

try
{
    Value result = await client.Query(
        Delete(Index("all_of_the_people"))
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
ObjectV(ref: RefV(id = "all_of_the_people", collection = RefV(id = "indexes")),ts: LongV(1632032541470000),active: BooleanV(True),serialized: BooleanV(True),name: StringV(all_of_the_people),source: RefV(id = "People", collection = RefV(id = "collections")),values: Arr(ObjectV(field: Arr(StringV(data), StringV(first))), ObjectV(field: Arr(StringV(data), StringV(last))), ObjectV(field: Arr(StringV(ref)))),partitions: LongV(8),data: ObjectV(team: StringV(Wizards)))
result, err := client.Query(
	f.Delete(f.Index("all_of_the_people")))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
map[active:true data:map[team:Wizards] name:all_of_the_people partitions:8 ref:{all_of_the_people 0xc0001804b0 0xc0001804b0 <nil>} serialized:true source:{People 0xc0001805a0 0xc0001805a0 <nil>} ts:1631911525160000 values:[map[field:[data first]] map[field:[data last]] map[field:[ref]]]]
System.out.println(
    client.query(
        Delete(Index("all_of_the_people"))
    ).get());
{ref: ref(id = "all_of_the_people", collection = ref(id = "indexes")), ts: 1632028355020000, active: true, serialized: true, name: "all_of_the_people", source: ref(id = "People", collection = ref(id = "collections")), values: [{field: ["data", "first"]}, {field: ["data", "last"]}, {field: ["ref"]}], partitions: 8, data: {team: "Wizards"}}
client.query(
  q.Delete(q.Index('all_of_the_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_of_the_people"),
  ts: 1631909688850000,
  active: true,
  serialized: true,
  name: 'all_of_the_people',
  source: Collection("People"),
  values: [
    { field: [ 'data', 'first' ] },
    { field: [ 'data', 'last' ] },
    { field: [ 'ref' ] }
  ],
  partitions: 8,
  data: { team: 'Wizards' }
}
result = client.query(
  q.delete(q.index("all_of_the_people"))
)
print(result)
{'ref': Ref(id=all_of_the_people, collection=Ref(id=indexes)), 'ts': 1631911056420000, 'active': True, 'serialized': True, 'name': 'all_of_the_people', 'source': Ref(id=People, collection=Ref(id=collections)), 'values': [{'field': ['data', 'first']}, {'field': ['data', 'last']}, {'field': ['ref']}], 'partitions': 8, 'data': {'team': 'Wizards'}}
Delete(Index('all_of_the_people'))
{
  ref: Index("all_of_the_people"),
  ts: 1631836244370000,
  active: true,
  serialized: true,
  name: 'all_of_the_people',
  source: Collection("People"),
  values: [
    { field: [ 'data', 'first' ] },
    { field: [ 'data', 'last' ] },
    { field: [ 'ref' ] }
  ],
  partitions: 8,
  data: { team: 'Wizards' }
}
Query metrics:
  •    bytesIn:   40

  •   bytesOut:  376

  • computeOps:    1

  •    readOps:    0

  •   writeOps:    1

  •  readBytes:  554

  • writeBytes:  487

  •  queryTime: 54ms

  •    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!