mongodb-update-one

A “mongodb-update-one” tool updates a single document in a MongoDB collection.

About

A mongodb-update-one tool updates a single document within a specified MongoDB collection. It locates the document to be updated using a filterPayload and applies modifications defined in an updatePayload. If the filter matches multiple documents, only the first one found will be updated.

This tool is compatible with the following source kind:


Example

Here’s an example of a mongodb-update-one tool configuration. This tool updates the stock and status fields of a document in the inventory collection where the item field matches a provided value. If no matching document is found, the upsert: true option will create a new one.

tools:
  update_inventory_item:
    kind: mongodb-update-one
    source: my-mongo-source
    description: Use this tool to update an item's stock and status in the inventory.
    database: products
    collection: inventory
    filterPayload: |
        { "item": {{json .item_name}} }
    filterParams:
      - name: item_name
        type: string
        description: The name of the item to update.
    updatePayload: |
        { "$set": { "stock": {{json .new_stock}}, "status": {{json .new_status}} } }
    updateParams:
      - name: new_stock
        type: integer
        description: The new stock quantity.
      - name: new_status
        type: string
        description: The new status of the item (e.g., "In Stock", "Backordered").
    canonical: false
    upsert: true

Reference

fieldtyperequireddescription
kindstringtrueMust be mongodb-update-one.
sourcestringtrueThe name of the mongodb source to use.
descriptionstringtrueA description of the tool that is passed to the LLM.
databasestringtrueThe name of the MongoDB database containing the collection.
collectionstringtrueThe name of the MongoDB collection to update a document in.
filterPayloadstringtrueThe MongoDB query filter document to select the document for updating. It’s written as a Go template, using {{json .param_name}} to insert parameters.
filterParamslisttrueA list of parameter objects that define the variables used in the filterPayload.
updatePayloadstringtrueThe MongoDB update document, which specifies the modifications. This often uses update operators like $set. It’s written as a Go template, using {{json .param_name}} to insert parameters.
updateParamslisttrueA list of parameter objects that define the variables used in the updatePayload.
canonicalbooltrueDetermines if the updatePayload string is parsed using MongoDB’s Canonical or Relaxed Extended JSON format. Canonical is stricter about type representation (e.g., {"$numberInt": "42"}), while Relaxed is more lenient (e.g., 42).
upsertboolfalseIf true, a new document is created if no document matches the filterPayload. Defaults to false.
Last modified July 25, 2025: docs: update docs lint (#995) (90d4558a8)