Index is not working for specific collection

Hello, folks, is so nice to being use Fauna, I’ve been using it since I started this personal project (as per Fireship’s Youtube channel, it’s awesome indeed), I even recommended the company I’m working to use it.

Right now, I’m having a strange problem. I’m trying to update and delete a document, based on an index. I’ve done that for several collections (entities), but this specific one is not working.
This is the error I’m getting:

Error: [
  {
    "position": [],
    "code": "instance not found",
    "description": "Set not found."
  }
]

image

This is my collection:

{
  "ref": Ref(Collection("units"), "327742118188548163"),
  "ts": 1648818090540000,
  "data": {
    "id": "a8293d39-01bc-4f43-bb80-2f0c528422d1",
    "name": "Matriz",
    "location": "Piracicaba - São Paulo",
    "address": "Rua Dona Eugênia, 402. Jardim Europa - Piracicaba, São Paulo. CEP 13416-401.",
  }
}

It uses an index for it’s id behind the scenes, here it is:
index

My queries are:

update -

Update(
        Select(['ref'], Get(Match(Index('unit_by_id'), updateUnitDto.id))),
        {
          data: updateUnitDto,
        },
      ),

delete -
Delete(Select(['ref'], Get(Match(Index('unit_by_id'), id))))

Strangely enough, I’m using the same queries for updating/deleting records from multiple collections, all work, but this one. I’m already aware of the issue mentioned by @ptpaterson at Instance not found even though instance exists and unique rule being ignored - #5 by aprilmintacpineda, regarding indexes caching.
The problem is that I’ve already created this index 3 hours ago, it’s still not working. I’ve also tried running the query in the shell, but I’m still getting the error (please see it attached in the comment below, as a new user, I can only post one embedded media per post)

Is there anything really obvious that I’m missing? Is 3 hours not enough for the cache of indexes to be updated?

Thanks in advance for your support.

Hi @dinaiscoding. From the looks of the screenshot of your Index, the Index does not include the Ref you need in the values. Instead of the Ref, it is returning your business ID.

Can you share the definition of your Index? You can navigate to your Index settings in the Dashboard or run the following in the shell

Get(Index("unit_by_id"))

For your query to work, I would expect it would need to look something like this:

{
  name: "unit_by_id",
  source: Collection("units"),
  terms: [
    { field: ["data", "id"] },
  ],
  values: [
    // looks like you currently only specify `["data", "id"]`
    { /* some values */ }
    { field: ["ref"] }  // <-- need to `Get` this Ref
  ]
}

EDIT: I had terms defined twice in the example. I meant to define values as well. It is also possible to leave values undefined if the only value that you need is the Ref.

{
  name: "unit_by_id",
  source: Collection("units"),
  terms: [
    { field: ["data", "id"] },
  ]
  // default value is just the Ref 
}

Hello @ptpaterson , thanks for your prompt support. I’ve noticed that the terms field was missing in my index, so I mistook the terms with the values :man_facepalming:
Either way, I’ve corrected the index. Thanks once again for your awesome support :muscle:

2 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.