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
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
collection | string | no | The collection to watch. Without it, the stream gives the changes of the database. | |
database | string | no | The database name (default: the database of the connection) | |
pipeline | object[] | no | Stages after the change stream stage: $match, $project, $addFields, $set, $unset, $replaceRoot, $replaceWith, $redact | |
fullDocument | "default" | "updateLookup" | "whenAvailable" | "required" | no | The full document of an update: updateLookup reads it (default: none) | |
resumeAfter | string | no | The resume token of an earlier change: the stream starts after it |
Output
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
operationType | string | yes | insert, update, replace, delete, drop, rename, dropDatabase or invalidate | |
ns | object | no | The database and the collection of the change | |
documentKey | object | no | The _id of the changed document | |
fullDocument | object | null | no | The document of an insert or a replace, and of an update with fullDocument | |
updateDescription | object | no | The changed and removed fields of an update | |
wallTime | string | no | The time of the change on the server (ISO 8601), from MongoDB 6.0 | |
resumeToken | string | yes | The 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": {}
}
}