< Back
Add-MdbcData
Post
NAME Add-MdbcData
SYNOPSIS
Adds new documents to the database collection.
SYNTAX
Add-MdbcData [[-InputObject] <PSObject>] [-Collection <IMongoCollection`1>] [-Convert <ScriptBlock>] [-Id
<PSObject>] [-Property <Object[]>] [-Session <IClientSessionHandle>] [-NewId] [<CommonParameters>]
DESCRIPTION
This command adds strictly new documents to the database collection. If an input document has the field _id which
already exists then the command writes an error.
PARAMETERS
-InputObject
Document or a similar object, see INPUTS.
Required? false
Position? 0
Default value
Accept pipeline input? true (ByValue)
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?
-Convert
A script called on conversion of unknown data types. The variable $_ represents the unknown object. The script
returns a new object suitable for conversion.
Examples: {} converts unknown data to nulls. {"$_"} converts data to strings.
Converters should be used sparingly, normally with unknown or varying data.
Required? false
Position? named
Default value
Accept pipeline input?
Accept wildcard characters?
-Id
Specifies the _id value of result document, either literally or using a script block returning this value for
the input object represented by the variable $_. The script block is used for multiple objects in the pipeline.
If Id is used then _id must not exist in input objects or Property.
Required? false
Position? named
Default value
Accept pipeline input?
Accept wildcard characters?
-NewId
Tells to assign _id to a new generated MongoDB.Bson.ObjectId.
If NewId is used then _id must not exist in input objects or Property.
Required? false
Position? named
Default value
Accept pipeline input?
Accept wildcard characters?
-Property
Specifies properties or keys which values are included into documents or defines calculated fields. Missing
input properties and keys are ignored.
If Property is omitted then types registered by Register-MdbcClassMap are serialized. Use `-Property *` in
order to convert by properties instead.
Arguments:
1. Strings define property or key names of input objects. Wildcards are not supported but "*" may be used in
order to tell "convert all properties".
2. Hashtables @{Key=Value} define renamed and calculated fields. The key is the result document field name.
The value is either a string (input object property or key) or a script block (field value calculated from the
input object $_).
3. Hashtables @{Name=...; Expression=...} or @{Label=...; Expression=...} are similar but follow the syntax of
`Select-Object -Property`.
See New-MdbcData examples.
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
[Mdbc.Dictionary]
Objects created by New-MdbcData or obtained by Get-MdbcData or Import-MdbcData. This type is the most
effective and safe as input/output of Mdbc data cmdlets.
[IDictionary]
Hashtables and other dictionaries are converted to new documents. Keys are strings used as field names. Nested
collections, dictionaries, and custom objects are converted to BSON documents and collections recursively.
Other values are converted to BSON values.
[PSObject]
Objects are converted to new documents. Property names are used as field names. Nested collections,
dictionaries, and custom objects are converted to BSON documents and collections recursively. Other values are
converted to BSON values.
$null
Null is converted to an empty document by New-MdbcData and ignored by Add-MdbcData and Export-MdbcData.
OUTPUTS
RELATED LINKS
New-MdbcData
Select-Object
SYNOPSIS
Adds new documents to the database collection.
SYNTAX
Add-MdbcData [[-InputObject] <PSObject>] [-Collection <IMongoCollection`1>] [-Convert <ScriptBlock>] [-Id
<PSObject>] [-Property <Object[]>] [-Session <IClientSessionHandle>] [-NewId] [<CommonParameters>]
DESCRIPTION
This command adds strictly new documents to the database collection. If an input document has the field _id which
already exists then the command writes an error.
PARAMETERS
-InputObject
Document or a similar object, see INPUTS.
Required? false
Position? 0
Default value
Accept pipeline input? true (ByValue)
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?
-Convert
A script called on conversion of unknown data types. The variable $_ represents the unknown object. The script
returns a new object suitable for conversion.
Examples: {} converts unknown data to nulls. {"$_"} converts data to strings.
Converters should be used sparingly, normally with unknown or varying data.
Required? false
Position? named
Default value
Accept pipeline input?
Accept wildcard characters?
-Id
Specifies the _id value of result document, either literally or using a script block returning this value for
the input object represented by the variable $_. The script block is used for multiple objects in the pipeline.
If Id is used then _id must not exist in input objects or Property.
Required? false
Position? named
Default value
Accept pipeline input?
Accept wildcard characters?
-NewId
Tells to assign _id to a new generated MongoDB.Bson.ObjectId.
If NewId is used then _id must not exist in input objects or Property.
Required? false
Position? named
Default value
Accept pipeline input?
Accept wildcard characters?
-Property
Specifies properties or keys which values are included into documents or defines calculated fields. Missing
input properties and keys are ignored.
If Property is omitted then types registered by Register-MdbcClassMap are serialized. Use `-Property *` in
order to convert by properties instead.
Arguments:
1. Strings define property or key names of input objects. Wildcards are not supported but "*" may be used in
order to tell "convert all properties".
2. Hashtables @{Key=Value} define renamed and calculated fields. The key is the result document field name.
The value is either a string (input object property or key) or a script block (field value calculated from the
input object $_).
3. Hashtables @{Name=...; Expression=...} or @{Label=...; Expression=...} are similar but follow the syntax of
`Select-Object -Property`.
See New-MdbcData examples.
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
[Mdbc.Dictionary]
Objects created by New-MdbcData or obtained by Get-MdbcData or Import-MdbcData. This type is the most
effective and safe as input/output of Mdbc data cmdlets.
[IDictionary]
Hashtables and other dictionaries are converted to new documents. Keys are strings used as field names. Nested
collections, dictionaries, and custom objects are converted to BSON documents and collections recursively.
Other values are converted to BSON values.
[PSObject]
Objects are converted to new documents. Property names are used as field names. Nested collections,
dictionaries, and custom objects are converted to BSON documents and collections recursively. Other values are
converted to BSON values.
$null
Null is converted to an empty document by New-MdbcData and ignored by Add-MdbcData and Export-MdbcData.
OUTPUTS
RELATED LINKS
New-MdbcData
Select-Object