Update One

Update One node is designed to modify a single specific record in a database based on a given query. It's useful when you need to update the information of a particular document that matches specified conditions.

This node is particularly valuable when you want to modify a unique record or when you're certain that only one record should be updated based on your criteria. If multiple records match the query, only the first matching record will be updated.

Properties Panel

Field

Description

Required

Default

Node name

true

-

Database collection

Database collection in which you want to update a specific document

true

-

Query Snippet

Query to identify which document needs to be modified

false

-

Update Snippet

Object which which will be used to replace or update current document

true

-

Upsert

Insert if document does not exist

false

false

Usage

  1. Select the database collection you want to update.

  2. Define your query to match the desired record. For example: { "user_id": { "$eq": "12345" } }

  3. Specify the update snippet to apply the desired modifications. For example: { "$set": { "status": "active" } }

  4. Set the upsert option to true or false based on whether you want to create a new document if no match is found.

Returns

This node does not returns any value.

Example

Let's say you want to update a user's status to active based on their email address, and create the user if they don't exist:

  1. Set Database Collection to users

  2. Set Query to { "email": { "$eq": "user@example.com" } }

  3. Set Update snippet to { "$set": { "status": "active", "last_login": "2024-07-22T10:00:00Z" } }

  4. Set Upsert to true

This will either update an existing user's status and last login time, or create a new user with these details if no matching user is found.

Best Practices

  • Ensure your query is specific enough to target only the intended document.

  • Use atomic update operators (like $set, $inc, $push) to perform efficient updates without retrieving the entire document.

  • Be cautious when using upsert=true, as it can create new documents. Make sure your update snippet includes all necessary fields for a new document.

Last updated