Skip to content

Client errors when iterating over documents that contain & #62

@skedwards88

Description

@skedwards88

The following example errors at for (Document document : cursor) (even when the loop is empty) when one of the found documents has a field that includes &. I know about escaping & in field names, but I'm not sure where/how to escape in this case.

[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.6.2:java (default-cli) on project find-many-all-java: An exception occurred while executing the Java class. CLIENT_SERIALIZATION: [INVALID_EXPRESSION] - Invalid field expression: 'r&d':Single '&' must be followed by '.' to escape a dot or another '&' to represent '&'. (through reference chain: com.datastax.astra.internal.api.DataAPIResponse["data"]->com.datastax.astra.internal.api.DataAPIData["documents"]->java.util.ArrayList[14]->com.datastax.astra.client.collections.definition.documents.Document["r&d"]) -> [Help 1]
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.collections.Collection;
import com.datastax.astra.client.collections.commands.cursor.CollectionFindCursor;
import com.datastax.astra.client.collections.definition.documents.Document;
import com.datastax.astra.client.core.query.Filter;

public class Example {

  public static void main(String[] args) {
    // Get an existing collection
    Collection<Document> collection =
        new DataAPIClient(System.getenv("APPLICATION_TOKEN"))
            .getDatabase(System.getenv("API_ENDPOINT"))
            .getCollection("quickstart_collection");

    // Find documents
    CollectionFindCursor<Document, Document> cursor = collection.find((Filter) null);

    // Iterate over the found documents
    for (Document document : cursor) {
      System.out.println(document);
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions