< Back

Import-MdbcData

Sat Jan 18, 2020 11:32 am

NAME Import-MdbcData



SYNOPSIS

Imports data from a file.





SYNTAX

Import-MdbcData [-Path] <String> [-As <Object>] [-FileFormat <FileFormat>] [<CommonParameters>]





DESCRIPTION

The cmdlet reads data from a BSON file. Such files are produced, for example, by the cmdlet Export-MdbcData or by

the utility 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 BSON file where objects will be restored from.



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?



-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?



<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 default output type.



[object]

Custom type specified by the parameter As.





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



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

Import-MdbcData test.bson -As PS



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



# Import data produced by ConvertTo-Json (PowerShell V3)

Get-Process | ConvertTo-Json | Set-Content process.json

Import-MdbcData process.json





RELATED LINKS

Export-MdbcData