< Back
Invoke-MdbcAggregate
Post
NAME Invoke-MdbcAggregate
SYNOPSIS
Invokes aggregate operations.
SYNTAX
Invoke-MdbcAggregate [-Pipeline] <Object> [-As <Object>] [-Collection <IMongoCollection`1>] [-Options
<AggregateOptions>] [-Session <IClientSessionHandle>] [<CommonParameters>]
Invoke-MdbcAggregate [-Group] <Object> [-As <Object>] [-Collection <IMongoCollection`1>] [-Options
<AggregateOptions>] [-Session <IClientSessionHandle>] [<CommonParameters>]
DESCRIPTION
The cmdlet invokes the aggregation pipeline for the specified or default collection.
PARAMETERS
-Group
Specifies the low ceremony aggregate pipeline of just $group. The argument is the $group expression, either
JSON or similar dictionary.
If the expression omits the grouping _id then null is used. This form is useful for calculating $max, $min,
$sum, etc. of all field values, see examples.
Required? true
Position? 0
Default value
Accept pipeline input?
Accept wildcard characters?
-Pipeline
One or more aggregation pipeline operations represented by JSON or similar dictionaries.
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?
-Collection
Collection instance. If it is omitted then the variable $Collection is used. It is obtained by Connect-Mdbc,
Get-MdbcCollection, or using the driver API.
Required? false
Position? named
Default value
Accept pipeline input?
Accept wildcard characters?
-Options
Extra options, see MongoDB.Driver.AggregateOptions
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]
Result documents wrapped by Mdbc.Dictionary.
[object]
Other object types depending on As.
-------------------------- EXAMPLE 1 --------------------------
# Data: current process names and memory working sets
# Group by names, count, sum memory, get top 3 memory
Connect-Mdbc . test test -NewCollection
Get-Process | Add-MdbcData -Property Name, WorkingSet
Invoke-MdbcAggregate @(
@{ '$group' = @{
_id = '$Name'
Count = @{ '$sum' = 1 }
Memory = @{ '$sum' = '$WorkingSet' }
}}
@{ '$sort' = @{Memory = -1} }
@{ '$limit' = 3 }
)
-------------------------- EXAMPLE 2 --------------------------
# Get the minimum and maximum values of the field .price:
Invoke-MdbcAggregate -Group '{min: {$min: "$price"}, max: {$max: "$price"}}'
# Get maximum prices by categories:
Invoke-MdbcAggregate -Group '{_id: "$category", price: {$max: "$price"}}'
RELATED LINKS
SYNOPSIS
Invokes aggregate operations.
SYNTAX
Invoke-MdbcAggregate [-Pipeline] <Object> [-As <Object>] [-Collection <IMongoCollection`1>] [-Options
<AggregateOptions>] [-Session <IClientSessionHandle>] [<CommonParameters>]
Invoke-MdbcAggregate [-Group] <Object> [-As <Object>] [-Collection <IMongoCollection`1>] [-Options
<AggregateOptions>] [-Session <IClientSessionHandle>] [<CommonParameters>]
DESCRIPTION
The cmdlet invokes the aggregation pipeline for the specified or default collection.
PARAMETERS
-Group
Specifies the low ceremony aggregate pipeline of just $group. The argument is the $group expression, either
JSON or similar dictionary.
If the expression omits the grouping _id then null is used. This form is useful for calculating $max, $min,
$sum, etc. of all field values, see examples.
Required? true
Position? 0
Default value
Accept pipeline input?
Accept wildcard characters?
-Pipeline
One or more aggregation pipeline operations represented by JSON or similar dictionaries.
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?
-Collection
Collection instance. If it is omitted then the variable $Collection is used. It is obtained by Connect-Mdbc,
Get-MdbcCollection, or using the driver API.
Required? false
Position? named
Default value
Accept pipeline input?
Accept wildcard characters?
-Options
Extra options, see MongoDB.Driver.AggregateOptions
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]
Result documents wrapped by Mdbc.Dictionary.
[object]
Other object types depending on As.
-------------------------- EXAMPLE 1 --------------------------
# Data: current process names and memory working sets
# Group by names, count, sum memory, get top 3 memory
Connect-Mdbc . test test -NewCollection
Get-Process | Add-MdbcData -Property Name, WorkingSet
Invoke-MdbcAggregate @(
@{ '$group' = @{
_id = '$Name'
Count = @{ '$sum' = 1 }
Memory = @{ '$sum' = '$WorkingSet' }
}}
@{ '$sort' = @{Memory = -1} }
@{ '$limit' = 3 }
)
-------------------------- EXAMPLE 2 --------------------------
# Get the minimum and maximum values of the field .price:
Invoke-MdbcAggregate -Group '{min: {$min: "$price"}, max: {$max: "$price"}}'
# Get maximum prices by categories:
Invoke-MdbcAggregate -Group '{_id: "$category", price: {$max: "$price"}}'
RELATED LINKS