< Back
Use-MdbcTransaction
Post
NAME Use-MdbcTransaction
SYNOPSIS
Invokes the script with a transaction.
SYNTAX
Use-MdbcTransaction [-Script] <ScriptBlock> [-Client <MongoClient>] [<CommonParameters>]
DESCRIPTION
** For replicas and shards only **
The cmdlet starts a transaction session and invokes the specified script. The script calls data cmdlets and either
succeeds or fails. The cmdlet commits or aborts the transaction accordingly.
The transaction session is default for cmdlets with the parameter Session. For the script the session is exposed
as the automatic variable $Session.
Nested calls are allowed but transactions and sessions are independent. In particular, they may not see changes
made in parent or nested calls.
PARAMETERS
-Script
Specifies the script to be invoked with a transaction session.
Required? true
Position? 0
Default value
Accept pipeline input?
Accept wildcard characters?
-Client
Client instance. If it is omitted then the variable $Client is used. It is obtained by Connect-Mdbc or using
the driver API.
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
[object]
Output of the specified script.
-------------------------- EXAMPLE 1 --------------------------
# add several documents using a transaction
$documents = ...
Use-MdbcTransaction {
$documents | Add-MdbcData
}
-------------------------- EXAMPLE 2 --------------------------
# move a document using a transaction
$c1 = Get-MdbcCollection MyData1
$c2 = Get-MdbcCollection MyData2
Use-MdbcTransaction {
# get and remove from MyData1 | add to MyData2
Get-MdbcData @{_id = 1} -Remove -Collection $c1 |
Add-MdbcData -Collection $c2
}
RELATED LINKS
SYNOPSIS
Invokes the script with a transaction.
SYNTAX
Use-MdbcTransaction [-Script] <ScriptBlock> [-Client <MongoClient>] [<CommonParameters>]
DESCRIPTION
** For replicas and shards only **
The cmdlet starts a transaction session and invokes the specified script. The script calls data cmdlets and either
succeeds or fails. The cmdlet commits or aborts the transaction accordingly.
The transaction session is default for cmdlets with the parameter Session. For the script the session is exposed
as the automatic variable $Session.
Nested calls are allowed but transactions and sessions are independent. In particular, they may not see changes
made in parent or nested calls.
PARAMETERS
-Script
Specifies the script to be invoked with a transaction session.
Required? true
Position? 0
Default value
Accept pipeline input?
Accept wildcard characters?
-Client
Client instance. If it is omitted then the variable $Client is used. It is obtained by Connect-Mdbc or using
the driver API.
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
[object]
Output of the specified script.
-------------------------- EXAMPLE 1 --------------------------
# add several documents using a transaction
$documents = ...
Use-MdbcTransaction {
$documents | Add-MdbcData
}
-------------------------- EXAMPLE 2 --------------------------
# move a document using a transaction
$c1 = Get-MdbcCollection MyData1
$c2 = Get-MdbcCollection MyData2
Use-MdbcTransaction {
# get and remove from MyData1 | add to MyData2
Get-MdbcData @{_id = 1} -Remove -Collection $c1 |
Add-MdbcData -Collection $c2
}
RELATED LINKS