Astra DB icon

Astra DB

Interact with DataStax Astra DB collections for document operations

Find And Replace Document

AI-generated

Summary

Find and replace a document in an Astra DB collection based on specified filter criteria.

Inputs

  • keyspace (required) — The name of the Astra DB keyspace to operate on.
  • collection (required) — The name of the Astra DB collection to find and replace the document.
  • filter (required) — JSON criteria to find the document that needs to be replaced.
  • replacement (required) — JSON document that will replace the found document.
  • options — Additional options for the operation, such as projection and return document settings.

Output shape

a confirmation of the replace operation or the document based on return settings

Returned document can either be the state before or after the replacement, dependent on the 'Return Document' option.

Examples

Example 1: Replace a document with specific fields while maintaining certain attributes from the original if no match is found.

Configure the keyspace and collection, provide filter and replacement JSON, and set options for projection and return document.

Discussion