MongoDB.WatchClient
-------------------

Creates a change stream for a client.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [MongoDB](component_MongoDB.md) | [13.0](newinversion130.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "MongoDB.WatchClient"; MongoDBRef; pipelineJSON { ; OptionsJSON } ) 

**MBS**( **"MongoDB.WatchClient";** /\* Creates a change stream for a client. \*/  
**$MongoDBRef**; /\* The reference number for the mongo connection.e.g. $MongoDB \*/   
**$pipelineJSON**; /\* A JSON representing an aggregation pipeline appended to the change stream. This may be an empty document.e.g. "{}" \*/   
**$OptionsJSON**) /\* Optional; A JSON containing change stream options. options may be "" or a JSON document with additional command options.e.g. "" \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| MongoDBRef | The reference number for the mongo connection. | $MongoDB |  |
| pipelineJSON | A JSON representing an aggregation pipeline appended to the change stream. This may be an empty document. | "{}" |  |
| OptionsJSON | A JSON containing change stream options. options may be "" or a JSON document with additional command options. | "" | Optional |

### Result

Returns OK or error.

### Description

Creates a change stream for a client.  
It is preferred to call this function over using a raw aggregation to create a change stream.  
  
This function uses the read preference and read concern of the client. If the change stream needs to re-establish connection, the same read preference will be used. This may happen if the change stream encounters a resumable error.  
  
Warning A change stream is only supported with majority read concern.  
This function is considered a retryable read operation. Upon a transient error (a network error, errors due to replica set failover, etc.) the operation is safely retried once. If retryreads is false in the URI the retry behavior does not apply.  
  
Call this method on the client which the change stream listens to.  
  
pipelineJSON: A JSON representing an aggregation pipeline appended to the change stream. This may be an empty document.  
  
OptionsJSON: A JSON containing change stream options. options may be "" or a JSON document with additional command options:  
  
batchSize: An integer representing number of documents requested to be returned on each call to NextChange()  
  
resumeAfter: A Document representing the logical starting point of the change stream. The result of StreamResumeToken() or the \_id field of any change received from a change stream can be used here. This option is mutually exclusive with startAfter and startAtOperationTime.  
  
startAfter: A Document representing the logical starting point of the change stream. Unlike resumeAfter, this can resume notifications after an "invalidate" event. The result of StreamResumeToken() or the \_id field of any change received from a change stream can be used here. This option is mutually exclusive with resumeAfter and startAtOperationTime.  
  
startAtOperationTime: A Timestamp. The change stream only provides changes that occurred at or after the specified timestamp. Any command run against the server will return an operation time that can be used here. This option is mutually exclusive with resumeAfter and startAfter.  
  
maxAwaitTimeMS: An int64 representing the maximum amount of time a call to StreamResumeToken() will block waiting for data  
  
fullDocument: An optional UTF-8 string. Set this option to "default", "updateLookup", "whenAvailable", or "required", If unset, The string "default" is assumed. Set this option to "updateLookup" to direct the change stream cursor to lookup the most current majority-committed version of the document associated to an update change stream event.  
  
fullDocumentBeforeChange: An optional UTF-8 string. Set this option to "whenAvailable", "required", or "off". When unset, the default value is "off". Similar to "fullDocument", but returns the value of the document before the associated change.  
  
comment: A JSON specifying the comment to attach to this command. The comment will appear in log messages, profiler output, and currentOp output. Only string values are supported prior to MongoDB 4.4.  
### Release notes

- **Version 13.0**
    - Added functions to watch changes in MongoDB: [MongoDB.ChangeStreamErrorDocument](https://www.mbsplugins.eu/MongoDBChangeStreamErrorDocument.shtml), [MongoDB.ChangeStreamResumeToken](https://www.mbsplugins.eu/MongoDBChangeStreamResumeToken.shtml), [MongoDB.CloseChangeStream](https://www.mbsplugins.eu/MongoDBCloseChangeStream.shtml), [MongoDB.NextChange](https://www.mbsplugins.eu/MongoDBNextChange.shtml), [MongoDB.WatchClient](https://www.mbsplugins.eu/MongoDBWatchClient.shtml), [MongoDB.WatchCollection](https://www.mbsplugins.eu/MongoDBWatchCollection.shtml) and [MongoDB.WatchDatabase](https://www.mbsplugins.eu/MongoDBWatchDatabase.shtml).

### Blog Entries

- [Watch MongoDB Database](https://www.mbsplugins.de/archive/2023-11-04/Watch_MongoDB_Database/monkeybreadsoftware_blog_filemaker)
- [New in MBS FileMaker Plugin 13.0](https://www.mbsplugins.de/archive/2023-01-24/New_in_MBS_FileMaker_Plugin_13/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 12.6pr1](https://www.mbsplugins.de/archive/2022-12-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 18th November 2022 , last changed 18th November 2022

  
[MongoDB.UpdateOne](MongoDBUpdateOne.md) - [MongoDB.WatchCollection](MongoDBWatchCollection.md)

[HTML Version](MongoDBWatchClient.shtml)