< Back

Connect-Mdbc

Sat Jan 18, 2020 11:32 am

NAME Connect-Mdbc



SYNOPSIS

Connects the client, database, and collection.





SYNTAX

Connect-Mdbc [[-ConnectionString] <String>] [[-DatabaseName] <String>] [[-CollectionName] <String>]

[-ClientVariable <String>] [-CollectionVariable <String>] [-DatabaseVariable <String>] [-NewCollection]

[<CommonParameters>]





DESCRIPTION

The cmdlet connects to the specified server and creates the variables for client, database, and collection in the

current scope. By default they are $Client, $Database, and $Collection.



If none of the parameters ConnectionString, DatabaseName, CollectionName is specified then they are assumed to be

".", "test", "test" respectively.





PARAMETERS

-ConnectionString

Connection string (see driver manuals for details):

mongodb://[username:password@]hostname[:port][/[database][?options]]



"." is used for the default driver connection.



Examples:

mongodb://localhost:27017

mongodb://myaccount:mypass@remotehost.example.com



Required? false

Position? 0

Default value

Accept pipeline input?

Accept wildcard characters?



-DatabaseName

Database name. Use * in order to get available names.



Required? false

Position? 1

Default value

Accept pipeline input?

Accept wildcard characters?



-CollectionName

Collection name. Use * in order to get available names.



Required? false

Position? 2

Default value

Accept pipeline input?

Accept wildcard characters?



-ClientVariable

Name of a new variable in the current scope with the connected client. The default variable is $Client.

Cmdlets with the parameter Client use it as the default value.



Required? false

Position? named

Default value

Accept pipeline input?

Accept wildcard characters?



-CollectionVariable

Name of a new variable in the current scope with the connected collection. The default variable is

$Collection. Cmdlets with the parameter Collection use it as the default value.



Required? false

Position? named

Default value

Accept pipeline input?

Accept wildcard characters?



-DatabaseVariable

Name of a new variable in the current scope with the connected database. The default variable is $Database.

Cmdlets with the parameter Database use it as the default value.



Required? false

Position? named

Default value

Accept pipeline input?

Accept wildcard characters?



-NewCollection

Tells to remove an existing collection before connecting the specified.



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

None or database or collection names.





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



# Connect a new collection (drop existing)

Import-Module Mdbc

Connect-Mdbc . test test -NewCollection



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



# Connect the database `test`

Import-Module Mdbc

Connect-Mdbc . test



# Then get collections

$collection1 = Get-MdbcCollection test

$collection2 = Get-MdbcCollection process



-------------------------- EXAMPLE 3 --------------------------



# Connect the client

Import-Module Mdbc

Connect-Mdbc mongodb://localhost



# Then get the database

$Database = Get-MdbcDatabase test



-------------------------- EXAMPLE 4 --------------------------



# Connect the local and get databases

Import-Module Mdbc

Connect-Mdbc . *



-------------------------- EXAMPLE 5 --------------------------



# Connect the database 'test' and get collections

Import-Module Mdbc

Connect-Mdbc . test *





RELATED LINKS

Add-MdbcData

Get-MdbcData

Remove-MdbcData

Update-MdbcData

MongoDB http://www.mongodb.org