< Back

Export-MdbcData

Sat Jan 18, 2020 11:32 am

NAME Export-MdbcData



SYNOPSIS

Exports objects to a BSON file.





SYNTAX

Export-MdbcData [-Path] <String> [[-InputObject] <PSObject>] [-Convert <ScriptBlock>] [-FileFormat <FileFormat>]

[-Id <PSObject>] [-Property <Object[]>] [-Retry <TimeSpan[]>] [-Append] [-NewId] [<CommonParameters>]





DESCRIPTION

The cmdlet writes BSON representation of input objects to the specified file. The output file has the same format

as .bson files produced by mongodump.exe.



Cmdlets Export-MdbcData and Import-MdbcData do not need any database connection or even MongoDB installed. They

are used for file based object persistence on their own.





PARAMETERS

-Path

Specifies the path to the file where BSON representation of objects will be stored.



Required? true

Position? 0

Default value

Accept pipeline input?

Accept wildcard characters?



-InputObject

Document or a similar object, see INPUTS.



Required? false

Position? 1

Default value

Accept pipeline input? true (ByValue)

Accept wildcard characters?



-Append

Tells to append data to the file if it exists.



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?



-FileFormat

Specifies the data file format:



Bson

BSON format



Json

JSON format



Auto (default)

The format is defined by the file extension: ".json" is for JSON,

other extensions are for BSON.



Input JSON is a sequence of objects and arrays of objects. Arrays are unrolled. Top objects and arrays are

optionally separated by spaces, tabs, and new lines.



Values : Auto, Bson, Json



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?



-Retry

Tells to retry on failures to open the file and specifies one or two arguments. The first is the retry

timeout. The second is the retry interval, the default is 50 milliseconds.



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



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



@{ p1 = 'Name1'; p2 = 42 }, @{ p1 = 'Name2'; p2 = 3.14 } | Export-MdbcData test.bson

Import-MdbcData test.bson -As PS



-------------------------- EXAMPLE 2 --------------------------



# "Safe" logging by several writers

$data | Export-MdbcData $file -Append -Retry ([TimeSpan]::FromSeconds(10))





RELATED LINKS

Import-MdbcData