I am running a local instance of Fauna which I access through a Netlify app. I have a collection (users) with an index (users_by_username) with one record which I can access through fauna shell using the secret used in my app
users.users_by_username("fred")
giving the result
{
data: [
{
id: "650044333971413209",
coll: users,
ts: Time("2024-01-02T12:31:20.100Z"),
first_name: "Fred",
last_name: "Dibnah",
login_id: "123621b8-d6fc-465e-90ae-dca8d83e3321x",
email: "jeff@xmail.com",
username: "fred",
contacts: []
}
]
}
However when I attempt to access it through the app I get an error
when reading user: Ref refers to undefined index ‘users_by_username’
The code here is cut down to a minimum
db-access.js in …/netlify/functions
var fclient = new faunadb.Client(
{
secret: 'fnAFWr6 ....',
domain: 'localhost',
port: '8443',
scheme: 'http',
}
)
exports.handler = async () => {
var query = faunadb.query
try {
var query_function = query.Map(
query.Paginate(query.Match(query.Index('users_by_username'), 'fred')),
(recordRef) => query.Get(recordRef)
);
var response = await fclient.query(query_function);
return {
statusCode: 200,
body: JSON.stringify(response.data),
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Credentials": true,
},
};
} catch (error) {
return {
statusCode: 422,
body: JSON.stringify(error),
};
};
};
Why can it not find the index?