< Back
Invoke-MdbcCommand
Post
NAME Invoke-MdbcCommand
SYNOPSIS
Invokes database commands.
SYNTAX
Invoke-MdbcCommand [-Command] <Object> [-As <Object>] [-Database <IMongoDatabase>] [-Session
<IClientSessionHandle>] [<CommonParameters>]
DESCRIPTION
This cmdlet is useful in order to invoke commands not covered by the module. See MongoDB for available commands
and syntax.
PARAMETERS
-Command
Specifies the command to be invoked. The argument is JSON, ordered dictionary, Mdbc.Dictionary, one item
hashtable.
JSON:
Invoke-MdbcCommand '{create: "test", capped: true, size: 10485760}'
Ordered dictionary:
Invoke-MdbcCommand ([ordered]@{create='test'; capped=$true; size=10mb })
Mdbc.Dictionary, ordered by definition:
$c = New-MdbcData
$c.create = 'test'
$c.capped = $true
$c.size = 10mb
Invoke-MdbcCommand $c
Required? true
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?
-Database
Database instance. If it is omitted then the variable $Database is used. It is obtained by Connect-Mdbc,
Get-MdbcDatabase, or using the driver API.
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
[Mdbc.Dictionary]
The response document wrapped by Mdbc.Dictionary.
[object]
Other object type depending on As.
-------------------------- EXAMPLE 1 --------------------------
# Get the server status, one item hashtable is fine
Connect-Mdbc . test
Invoke-MdbcCommand @{serverStatus = 1}
-------------------------- EXAMPLE 2 --------------------------
# Connect the database `test`, get statistics for the collection
# `test.test`. Mind [ordered], otherwise the command may fail:
# "`scale` is unknown command".
Connect-Mdbc . test
Invoke-MdbcCommand ([ordered]@{collStats = "test"; scale = 1mb})
-------------------------- EXAMPLE 3 --------------------------
# Connect the database `test` and invoke the command with
# the database `admin` specified explicitly (because the
# current is `test` and the command is admin-only)
Connect-Mdbc . test
Invoke-MdbcCommand @{getLog = 'global'} -Database (Get-MdbcDatabase admin)
-------------------------- EXAMPLE 4 --------------------------
# The example command creates a capped collection with maximum
# set to 5 documents, adds 10 documents, then gets all back (5
# documents are expected).
Connect-Mdbc . test test -NewCollection
$c = New-MdbcData
$c.create = 'test'
$c.capped = $true
$c.size = 1kb
$c.max = 5
$null = Invoke-MdbcCommand $c
# add 10 documents
foreach($_ in 1..10) {Add-MdbcData @{_id = $_}}
# get 5 documents
Get-MdbcData
RELATED LINKS
MongoDB http://www.mongodb.org
SYNOPSIS
Invokes database commands.
SYNTAX
Invoke-MdbcCommand [-Command] <Object> [-As <Object>] [-Database <IMongoDatabase>] [-Session
<IClientSessionHandle>] [<CommonParameters>]
DESCRIPTION
This cmdlet is useful in order to invoke commands not covered by the module. See MongoDB for available commands
and syntax.
PARAMETERS
-Command
Specifies the command to be invoked. The argument is JSON, ordered dictionary, Mdbc.Dictionary, one item
hashtable.
JSON:
Invoke-MdbcCommand '{create: "test", capped: true, size: 10485760}'
Ordered dictionary:
Invoke-MdbcCommand ([ordered]@{create='test'; capped=$true; size=10mb })
Mdbc.Dictionary, ordered by definition:
$c = New-MdbcData
$c.create = 'test'
$c.capped = $true
$c.size = 10mb
Invoke-MdbcCommand $c
Required? true
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?
-Database
Database instance. If it is omitted then the variable $Database is used. It is obtained by Connect-Mdbc,
Get-MdbcDatabase, or using the driver API.
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
[Mdbc.Dictionary]
The response document wrapped by Mdbc.Dictionary.
[object]
Other object type depending on As.
-------------------------- EXAMPLE 1 --------------------------
# Get the server status, one item hashtable is fine
Connect-Mdbc . test
Invoke-MdbcCommand @{serverStatus = 1}
-------------------------- EXAMPLE 2 --------------------------
# Connect the database `test`, get statistics for the collection
# `test.test`. Mind [ordered], otherwise the command may fail:
# "`scale` is unknown command".
Connect-Mdbc . test
Invoke-MdbcCommand ([ordered]@{collStats = "test"; scale = 1mb})
-------------------------- EXAMPLE 3 --------------------------
# Connect the database `test` and invoke the command with
# the database `admin` specified explicitly (because the
# current is `test` and the command is admin-only)
Connect-Mdbc . test
Invoke-MdbcCommand @{getLog = 'global'} -Database (Get-MdbcDatabase admin)
-------------------------- EXAMPLE 4 --------------------------
# The example command creates a capped collection with maximum
# set to 5 documents, adds 10 documents, then gets all back (5
# documents are expected).
Connect-Mdbc . test test -NewCollection
$c = New-MdbcData
$c.create = 'test'
$c.capped = $true
$c.size = 1kb
$c.max = 5
$null = Invoke-MdbcCommand $c
# add 10 documents
foreach($_ in 1..10) {Add-MdbcData @{_id = $_}}
# get 5 documents
Get-MdbcData
RELATED LINKS
MongoDB http://www.mongodb.org