Netlify Function with FaunaDB Query failed: Ref refers to undefined index

Help, I can’t figure out what went wrong.
Netlify Function with FaunaDB Query failed: Ref refers to undefined index

The outcome of deployed function is different to the outcome of localhost.

Outcome: /getUser?id=nik

{"build":1028,"message":"Query failed: Ref refers to undefined index 'users_id'"}

locahost: /getUser?id=nik

{"build":1028,"response":{"ref":{"@ref":{"id":"315756321428210252","collection":{"@ref":{"id":"users","collection":{"@ref":{"id":"collections"}}}}}},"ts":1637387544000000,"data":{"id":"nik"}}}

getUser.js

"use strict";

const { handle, json, message } = require('./utils/main');
const { q, client, getFaunaErrorMessage } = require('./utils/fauna');
const { env } = process, e=env;

const build=1028;

exports.handler = handle(async function(event,context) {

  const
  { id } = event.queryStringParameters;

  return client(
    q.Get(q.Match(q.Index("users_id"), id||'' ))
  )
  .then(response=>json(200,
    {
      build:build,
      response:response,
    }
  ))
  .catch(error=>{
    return json(500,{
      build:build,
      message:'Query failed: '+getFaunaErrorMessage(error)
    })
  })

})

Deployment

>netlify deploy --alias=1028
Deploy path:        \_site
Functions path:     \_functions
Configuration path: \netlify.toml
Deploying to draft URL...
√ No cached functions were found
√ Finished hashing 10 files and 2 functions
√ CDN requesting 0 files and 2 functions
√ Finished uploading 2 assets
√ Deploy is live!

Logs:              https://app.netlify.com/sites/droplets/deploys/619c4c6cb61e243bc617c82e
Website Draft URL: https://1028--droplets.netlify.app

FaunaDB: Running Shell Query with Server key
Outcome just fine.

Paginate(Collections())
Paginate(Indexes())
Get(Match(Index("users_id"), "nik"))

[
  {
    data: [Collection("users")]
  },
  {
    data: [Index("users_id")]
  },
  {
    ref: Ref(Collection("users"), "315756321428210252"),
    ts: 1637387544000000,
    data: {
      id: "nik"
    }
  }
]

I wonder what went wrong?

Hi @nikahmad,

Welcome to our forums!

It’s not clear what’s happening but we think it might be tied to your Netlify config. We’d like to review that with you, but don’t want you to share those details with the world at large. So, instead, please go to our helpdesk and open a ticket (you’ll need to create an account there, it’s not tied to the same auth system as the Fauna dashboard yet) and include a copy of your Netlify config file with it.

We’ll take a look and see if we can reproduce the error.

Thanks,
Cory

1 Like

Ok, I’ve sent a ticket #1175 to the Helpdesk regarding this matter. Thanks