Skip to content

Invalid query: Properties in where conditions must be defined as a document index #315

Closed

Description

@dashameter

I get the error:

InvalidRequestError: Invalid query: Properties in where conditions must be defined as a document index

with:

documents.get("dashpayWallet.chat", {
      where: [
        ["$ownerId", "==", myOwnerId],
        ["$createdAt", ">", lastTimestamp],
      ],
      orderBy: [["$createdAt", "asc"]],
    });

and the schema:

  "chat": {
    "type": "object",

    "indices": [
      {
        "name": "createdAt",
        "properties": [
          {
            "$createdAt": "asc"
          }
        ]
      },
      {
        "name": "$ownerId",
        "properties": [
          {
            "$ownerId": "asc"
          }
        ]
      },
...

I tried both ownerId and $ownerId as the name property in the schema.

tested with SDK v22.1 on dashmate and on testnet

Activity

  1. added
    bug
    on Mar 29, 2022
  2. dash-maverick commented on Apr 1, 2022

    @dash-maverick

    Suggestion from the team is that you need to try set this up as a single composed index, not as two separated. Considering those that are being used in where clause. Please try it out and get back with some feedback

  3. dashameter commented on Apr 8, 2022

    @dashameter
    ContributorAuthor

    retest passed, solution is:

      "chat": {
        "type": "object",
    
        "indices": [
          {
            "name": "$createdAt",
            "properties": [
              {
                "$createdAt": "asc"
              }
            ]
          },
          {
            "name": "$ownerIdAnd$createdAt",
            "properties": [
              {
                "$ownerId": "asc"
              },
              {
                "$createdAt": "asc"
              }
            ]
          },
    ...
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions