← All procedures

mongo.documents.update

Update documents matching a filter

MCPCLI
Package
@procedures/mongo · README
Path
["mongo","documents","update"]
CLI
mark mongo documents update --update <object>
MCP tool
mongo.documents.update on the dev-tools server
As data
{"$proc":["mongo","documents","update"],"input":{}}

Use it

In TypeScript

import { Client, LocalTransport, PROCEDURE_REGISTRY } from "@procedures/client";
import "@procedures/mongo"; // registers its procedures

const client = new Client(new LocalTransport({ registry: PROCEDURE_REGISTRY }));
const result = await client.exec(["mongo","documents","update"], { update: {} });
console.log(JSON.stringify(result));

From the command line

$ mark mongo documents update --update <object>

As data, in a program

{ "$proc": ["mongo", "documents", "update"], "input": { "update": {} } }

Input

FieldTypeRequiredDefaultDescription
collectionstringnoThe collection name. It takes the place of metadata.collection.
databasestringnoThe database name (default: the database of the connection)
filterobjectnoThe filter of the documents (give exactly one of id or filter). An empty filter needs confirm: true.
idstringnoThe id of one document (the alternative to filter)
idType"auto" | "objectId" | "string"noHow to read the id: "auto" (the default: an ObjectId or a string), "objectId" or "string"
multibooleannoChange every matching document, not only the first one
confirmbooleannoSet to true to use an empty filter, which matches every document
updateobjectyesThe update operations, for example { $set: { status: "done" } }
upsertbooleannoInsert a document when none matches

Output

FieldTypeRequiredDefaultDescription
acknowledgedbooleanyesTrue when the server confirmed the write
matchedCountnumberyesThe number of documents that matched
modifiedCountnumberyesThe number of documents that changed
upsertedIdstring | nullyesThe id of the new document of an upsert, as text, or null
upsertedCountnumberyesThe number of documents that an upsert made
JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "collection": {
        "description": "The collection name. It takes the place of metadata.collection.",
        "type": "string",
        "minLength": 1
      },
      "database": {
        "description": "The database name (default: the database of the connection)",
        "type": "string",
        "minLength": 1
      },
      "filter": {
        "description": "The filter of the documents (give exactly one of id or filter). An empty filter needs confirm: true.",
        "type": "object",
        "propertyNames": {
          "type": "string"
        },
        "additionalProperties": {}
      },
      "id": {
        "description": "The id of one document (the alternative to filter)",
        "type": "string",
        "minLength": 1
      },
      "idType": {
        "description": "How to read the id: \"auto\" (the default: an ObjectId or a string), \"objectId\" or \"string\"",
        "type": "string",
        "enum": [
          "auto",
          "objectId",
          "string"
        ]
      },
      "multi": {
        "description": "Change every matching document, not only the first one",
        "type": "boolean"
      },
      "confirm": {
        "description": "Set to true to use an empty filter, which matches every document",
        "type": "boolean"
      },
      "update": {
        "type": "object",
        "propertyNames": {
          "type": "string"
        },
        "additionalProperties": {},
        "description": "The update operations, for example { $set: { status: \"done\" } }"
      },
      "upsert": {
        "description": "Insert a document when none matches",
        "type": "boolean"
      }
    },
    "required": [
      "update"
    ]
  },
  "output": {
    "type": "object",
    "properties": {
      "acknowledged": {
        "type": "boolean",
        "description": "True when the server confirmed the write"
      },
      "matchedCount": {
        "type": "number",
        "description": "The number of documents that matched"
      },
      "modifiedCount": {
        "type": "number",
        "description": "The number of documents that changed"
      },
      "upsertedId": {
        "description": "The id of the new document of an upsert, as text, or null",
        "type": [
          "string",
          "null"
        ]
      },
      "upsertedCount": {
        "type": "number",
        "description": "The number of documents that an upsert made"
      }
    },
    "required": [
      "acknowledged",
      "matchedCount",
      "modifiedCount",
      "upsertedId",
      "upsertedCount"
    ],
    "additionalProperties": {}
  }
}