← All procedures

mongo.watch

The changes of a collection or a database, as a stream without an end (a change stream needs a replica set)

CLI
Package
@procedures/mongo · README
Path
["mongo","watch"]
CLI
mark mongo watch
As data
{"$proc":["mongo","watch"],"input":{}}

Use it

In TypeScript

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

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

From the command line

$ mark mongo watch

As data, in a program

{ "$proc": ["mongo", "watch"], "input": {} }

Input

FieldTypeRequiredDefaultDescription
collectionstringnoThe collection to watch. Without it, the stream gives the changes of the database.
databasestringnoThe database name (default: the database of the connection)
pipelineobject[]noStages after the change stream stage: $match, $project, $addFields, $set, $unset, $replaceRoot, $replaceWith, $redact
fullDocument"default" | "updateLookup" | "whenAvailable" | "required"noThe full document of an update: updateLookup reads it (default: none)
resumeAfterstringnoThe resume token of an earlier change: the stream starts after it

Output

FieldTypeRequiredDefaultDescription
operationTypestringyesinsert, update, replace, delete, drop, rename, dropDatabase or invalidate
nsobjectnoThe database and the collection of the change
documentKeyobjectnoThe _id of the changed document
fullDocumentobject | nullnoThe document of an insert or a replace, and of an update with fullDocument
updateDescriptionobjectnoThe changed and removed fields of an update
wallTimestringnoThe time of the change on the server (ISO 8601), from MongoDB 6.0
resumeTokenstringyesThe resume token of the change: resumeAfter takes it
JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "collection": {
        "description": "The collection to watch. Without it, the stream gives the changes of the database.",
        "type": "string",
        "minLength": 1
      },
      "database": {
        "description": "The database name (default: the database of the connection)",
        "type": "string",
        "minLength": 1
      },
      "pipeline": {
        "description": "Stages after the change stream stage: $match, $project, $addFields, $set, $unset, $replaceRoot, $replaceWith, $redact",
        "type": "array",
        "items": {
          "type": "object",
          "propertyNames": {
            "type": "string"
          },
          "additionalProperties": {}
        }
      },
      "fullDocument": {
        "description": "The full document of an update: updateLookup reads it (default: none)",
        "type": "string",
        "enum": [
          "default",
          "updateLookup",
          "whenAvailable",
          "required"
        ]
      },
      "resumeAfter": {
        "description": "The resume token of an earlier change: the stream starts after it",
        "type": "string",
        "minLength": 1
      }
    }
  },
  "output": {
    "type": "object",
    "properties": {
      "operationType": {
        "type": "string",
        "description": "insert, update, replace, delete, drop, rename, dropDatabase or invalidate"
      },
      "ns": {
        "description": "The database and the collection of the change",
        "type": "object",
        "properties": {
          "db": {
            "type": "string"
          },
          "coll": {
            "type": "string"
          }
        },
        "required": [
          "db"
        ],
        "additionalProperties": {}
      },
      "documentKey": {
        "description": "The _id of the changed document",
        "type": "object",
        "propertyNames": {
          "type": "string"
        },
        "additionalProperties": {}
      },
      "fullDocument": {
        "description": "The document of an insert or a replace, and of an update with fullDocument",
        "anyOf": [
          {
            "type": "object",
            "propertyNames": {
              "type": "string"
            },
            "additionalProperties": {}
          },
          {
            "type": "null"
          }
        ]
      },
      "updateDescription": {
        "description": "The changed and removed fields of an update",
        "type": "object",
        "propertyNames": {
          "type": "string"
        },
        "additionalProperties": {}
      },
      "wallTime": {
        "description": "The time of the change on the server (ISO 8601), from MongoDB 6.0",
        "type": "string"
      },
      "resumeToken": {
        "type": "string",
        "description": "The resume token of the change: resumeAfter takes it"
      }
    },
    "required": [
      "operationType",
      "resumeToken"
    ],
    "additionalProperties": {}
  }
}