Writing a reference with a non-existing Collection in a data property of a valid document fails (validation failed)

Has anything changed recently?


  1. create a tests collection
  2. create a new document in the tests collection with the following data:
  ref: Ref(Collection("users"), "123")

This will fail with:

  "errors": [
      "position": [],
      "code": "validation failed",
      "description": "document data is not valid.",
      "failures": [
          "field": [
          "code": "invalid reference",
          "description": "Cannot read reference."

Why couldn’t I save a reference that doesn’t exist (yet)? :thinking:
After all, it’s only a reference. It doesn’t pull anything.

(In general, it’s a reference that is being created within the query itself).

Use Case

Within the same query I want to:

  1. Create a collection
  2. Log the fact that the collection has been created in another collection

Turn around (for my use case)
(Sorry, just remembered)

    ref: Select("ref", CreateCollection({ name: 'users' })),
  Create(Collection('tests'), {
    data: {
      instance: q.Var('ref'),

You can’t reference a collection that’s doesn’t exist.

Based only on reading (a lot) of errors, I think that Document Refs and Schema Refs are treated differently.

Regular Class Ref expected, Schema Class Ref provided.

This one! :upside_down_face:

Anyways, that leads me to believe that you cannot reference any Schema documents that do not exists:

  • Collections
  • Indexes
  • Databases
  • Roles
  • Functions
  • Keys

So, there is my highly pedantic amendment to your answer. :nerd_face: