Find One

Find One node is designed to retrieve a single specific record from a database based on a given query. It's analogous to finding a particular piece of information that matches specified conditions.

This node is particularly useful when you need to fetch a unique record or when you're certain that only one record matches your criteria. If multiple records match the query, only the first matching record will be returned.

Properties Panel

Field

Description

Required

Node name

true

Database collection

Database collection in which you want to find that specific information

true

Query

Query to identify which documents needs to be modified

false

Projection

Specifies which fields to include or exclude in the result

false

Usage

  1. Select the database collection you want to search.

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

  3. (Optional) Specify a projection to include only relevant fields. For example: { "name": 1, "email": 1, "_id": 0 }

Returns

result - The matching document from the database. If no document matches the query, this will be null. You can access this using Magical Autocomplete (e.g. $.<node_name>.result) in any node below this node.

Example

Let's say you want to find a user by their email address and retrieve only their name and age:

  1. Set Database Collection to users

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

  3. Set Projection to { "name": 1, "age": 1, "_id": 0 }

This will return a result like:

{
  "name": "John Doe",
  "age": 30
}

Best Practices

  • Ensure your query is specific enough to return only one document, or be prepared to handle cases where the first matching document may not be the one you want.

  • Use indexing on frequently queried fields to improve performance.

  • Be cautious with projections to avoid exposing sensitive data.

Last updated