FaunaDB: Selecting all ID from a collection of documents

291 Views Asked by At

I need to list all id of documents in collection. I was following this:

https://docs.fauna.com/fauna/current/start/fql_for_sql_users.html?lang=javascript

In Sql what I want to do would be: SELECT id from Person

but in the example here, it will return all “columns” of Person. (SELECT * from Person)

How can I make an index that specify only id from the collections?

1

There are 1 best solutions below

0
On

You can create an Index with values = id.

For e.g.

{
  "shipperID" : 1,
  "companyName" : "Speedy Express",
  "phone" : "(503) 555-9831"
}
CreateIndex(
{
name: "shippers_id",
source: Collection("shippers"),
values:  [{field: ["data", "shipperID"]}]
})

SELECT shipperID FROM shippers in fql would be Paginate(Match(Index("shippers_id")))