Hey all! Just wanted to share a bug I'm facing and...
# community-help
s
Hey all! Just wanted to share a bug I'm facing and wondering if it was a known issue or I'm doing something wrong. I have 2 aliased collections and am trying to filter using a join. However, I get the error
Copy code
"Failed to join on `collection_2_alias`: No reference field found`
I've confirmed that re-creating the exact same collections without aliases leads to the queries behaving as expected. This only happens with aliases.
a
@Shawn Tan, Yes. When you reference a collection, the document will link to that document in memory. So if you change the alias, you have to reindex the data so it references the new collection, even if it is under the same alias.
s
Could you explain how I should trigger a reindex after changing alias?
@Alan Martini i've tried creating a new set of collections from scratch, with aliases. Even without changing the aliases, i'm seeing the same issue. I believe creating a new set of collections should be sufficient in term of re-indexing the documents?
a
@Shawn Tan, the collection created was the reference on the referenced? This issue happens when you use an alias to reference another collection: example:
Copy code
books_collection = books2932423
books_alias = books

{
  "name":  "authors",
  "fields": [
    {"name": "name", "type": "string"},
    {"name": "author_books", "type": "string", "reference": "books.id"}
  ]
}
In this case, if you create a new books collection and reference it as the new alias, the collection
authors
that will lose the reference and you must reindex
authors
. Do you mean even with a freshly created set of referencee and referenced this happens? Without changing alias?
s
Let me describe the workflow: First create 2 collections
Copy code
books_collection

{
  "name": "books",
  "fields": [{"name": "title"}]
}

authors_collection
{
  "name": "authors",
  "fields": [
    {"name": "name", "type": "string"},
    {"name": "books_written", "type": "string[]", "reference": "books.id", "async_references": true}
    ]
}
and then create the aliases
Copy code
aliases = {
  "books" -> "books_collection"
  "authors" -> "authors_collection"
}
and this query on books fails
Copy code
{
  "q": "*",
  "query_by": "title",
  "filter_by": "$authors(name:[Rowling])"
}
Now that i'm writing it, seems like the fact that the reference was created before alias assignment might be causing an issue? But I'm using async references because dependency might not be a DAG
a
Are you indexing the data after creating the aliases or before?
s
If my indexing the data you mean writing the data into documents, I'm doing it before aliases. Create collection -> write data -> create aliases
In this scenario i need to update aliases only after writing data / indexing because I'm planning to swap over the aliases after indexing is complete to minimize downtime when creating a new set of collections
a
I have to confirm wether the reference is genetated on collection definition or document indexing. Any chance you could make a reproducible example using the template below? Also, which version you're running? https://gist.github.com/jasonbosco/7c3432713216c378472f13e72246f46b
s
OK in trying to generate the template, i think i got to the bottom of it: • when trying to create the new collection, I'm using a reference that already exists • Even though i update the reference later, it's still pointing to the old collection • Updating the alias does not change the indexed reference I figured out a solution which is to use the non-aliased name when creating the schema for the new collection. Not sure if this is intended behavior, but glad to get to the bottom of this