Fixing "Missing Wildcard Definition" Error in FaunaDB Schema

I’m trying to define a users collection in FaunaDB with specific fields and a migration plan. However, I’m encountering the following error:

Error: “Missing wildcard definition”

It suggests that collections without explicitly defined fields allow arbitrary fields by default, and to maintain this behavior, I need to add a wildcard declaration (*: Any).

Here’s my schema:

collection users {
  history_days 30

  username: String
  email: String
  department: String
  name: String
  snakeGameScore: Number?

  migrations {
    add .username
    backfill .username = ""
    
    add .email
    backfill .email = ""
    
    add .department
    backfill .department = ""
    
    add .name
    backfill .name = ""

    add .snakeGameScore
    backfill .snakeGameScore = 0
  }
}

This is an existing collection that already contains around eight entries. The documents in this collection should contain only the defined fields (username, email, department, name, snakeGameScore) and no additional key-value pairs.

How can I resolve this issue while ensuring that my schema is correctly structured and enforces these field restrictions?

Hey @mls

Thanks for reaching out.

If a collection schema has no field definitions, it has an implicit *: Any top-level wildcard constraint. Documents can have any structure.

When you add new field definitions to a collection, you need to handle the top-level wildcard constraint explicitly. You can either:

It sounds like you want to remove the wildcard constraint. To do this, you’ll need to:

  1. Add a temporary catch-all field to handle any existing fields that don’t match the new schema.
  2. Migrate conflicting fields into this catch-all field.
  3. Remove the catch-all field.

This applies even if there are no actual conflicting fields in collection documents.

The following schema migration will accomplish that:

collection users {
  history_days 30

  username: String
  email: String
  department: String
  name: String
  snakeGameScore: Number?

  migrations {
    add .username
    backfill .username = ""
    
    add .email
    backfill .email = ""
    
    add .department
    backfill .department = ""
    
    add .name
    backfill .name = ""

    add .snakeGameScore
    backfill .snakeGameScore = 0

    // Add a temporary catch-all field for conflicting fields
    add .typeConflicts
    // Move existing conflicting 'typeConflicts' field values into '.typeConflicts'
    move_conflicts .typeConflicts
    // Move any fields not in the schema into '.typeConflicts'
    move_wildcard .typeConflicts
    // Remove the temporary '.typeConflicts' field
    drop .typeConflicts
  }
}
1 Like

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