< Back

Watch-MdbcChange

Sat Jan 18, 2020 11:33 am

NAME Watch-MdbcChange



SYNOPSIS

Gets the cursor for watching change events.





SYNTAX

Watch-MdbcChange [[-Pipeline] <Object>] -Client <IMongoClient> [-As <Object>] [-Options <ChangeStreamOptions>]

[-Session <IClientSessionHandle>] [<CommonParameters>]



Watch-MdbcChange [[-Pipeline] <Object>] -Collection <IMongoCollection`1> [-As <Object>] [-Options

<ChangeStreamOptions>] [-Session <IClientSessionHandle>] [<CommonParameters>]



Watch-MdbcChange [[-Pipeline] <Object>] -Database <IMongoDatabase> [-As <Object>] [-Options <ChangeStreamOptions>]

[-Session <IClientSessionHandle>] [<CommonParameters>]





DESCRIPTION

** For replicas and shards only **



The cmdlet returns the cursor for watching changes in the specified collection, database, or client.



Cursor members:



MoveNext() - Moves to the next batch of documents.

Current - Gets the current batch of documents.

Dispose() - Disposes the cursor after use.





PARAMETERS

-Pipeline

One or more aggregation pipeline operations represented by JSON or similar dictionaries.



Required? false

Position? 0

Default value

Accept pipeline input?

Accept wildcard characters?



-As

Specifies the type of output objects. The argument is either the type or full name or a special alias.



Key based types:

- [Mdbc.Dictionary] (alias "Default"), wrapper of BsonDocument

- [Hashtable] or other dictionaries, PowerShell native

- [Object], same as [System.Dynamic.ExpandoObject]

- [MongoDB.Bson.BsonDocument], driver native



Property based types:

- [PSObject] (alias "PS"), same as [PSCustomObject]

- Classes defined in PowerShell or .NET assemblies



Key based types and PSObject are schema free, they accept any result fields. Classes should match the result

fields, literally or according to the custom serialization.



Finally, some types are case sensitive (Mdbc.Dictionary, BsonDocument) and others are not, for example all

property based types in PowerShell.



Required? false

Position? named

Default value

Accept pipeline input?

Accept wildcard characters?



-Client

Specifies the client and tells to watch its changes.



Required? true

Position? named

Default value

Accept pipeline input?

Accept wildcard characters?



-Collection

Specifies the collection and tells to watch its changes.



Required? true

Position? named

Default value

Accept pipeline input?

Accept wildcard characters?



-Database

Specifies the database and tells to watch its changes.



Required? true

Position? named

Default value

Accept pipeline input?

Accept wildcard characters?



-Options

Extra options, see MongoDB.Driver.ChangeStreamOptions



Required? false

Position? named

Default value

Accept pipeline input?

Accept wildcard characters?



-Session

Specifies the client session which invokes the command.



If it is omitted then the cmdlet is invoked in the current default session, either its own or the transaction

session created by Use-MdbcTransaction.



Required? false

Position? named

Default value

Accept pipeline input?

Accept wildcard characters?



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS

[MongoDB.Driver.IAsyncCursor[object]]

Cursor of documents describing changes.





-------------------------- EXAMPLE 1 --------------------------



# get a new collection and watch its changes

Connect-Mdbc -NewCollection

$watch = Watch-MdbcChange -Collection $Collection

try {

# the first MoveNext "gets it ready"

$null = $watch.MoveNext()



# add and update some data

@{_id = 'count'; value = 0} | Add-MdbcData

Update-MdbcData @{_id = 'count'} @{'$inc' = @{value = 1}}



# get two documents about insert and update

if ($watch.MoveNext()) {

foreach($change in $watch.Current) {

"$change"

}

}

}

finally {

# dispose after use

$watch.Dispose()

}





RELATED LINKS