Project for extensions like cmdlet or providers for Windows-Powershell.
- .Net Framework >= 4.7.1
- PowerShell >= 5.1
This project is an extension for the Windows-Powershell and gives the easy possibility to work with a MongoDB-GridFs.
Install from Powershell Gallery (Install-Module -Name MongoDbGridFsProvider
) or just run the setup to install and register the provider on your system.
But if you want to try it first, without installation or as portable version, you can import the MongoDbGridFsProvider.psd1
with the Import-Module
by your own.
Check the MongoDbGridFs
Provider is correctly installed with
> Get-PSProvider
Name Capabilities Drives
---- ------------ ------
Registry ShouldProcess, Transactions {HKLM, HKCU}
Alias ShouldProcess {Alias}
Environment ShouldProcess {Env}
FileSystem Filter, ShouldProcess, Credentials {C, D, E, H...}
Function ShouldProcess {Function}
Variable ShouldProcess {Variable}
MongoDbGridFs Filter, ExpandWildcards, ShouldProcess, Credentials {NspMongo}
Certificate ShouldProcess {Cert}
WSMan Credentials {WSMan}
In order to use the provider, you must first register it.
> New-PSDrive -PSProvider MongoDbGridFs -Name Mongo -Root 'localhost' -Port '27017' -Database 'MyDb' -Collection 'fs.files' -Verify
Now the provider can simply be addressed by its name.
If credentials are required, set the parameter -Credential
with a PSCredential value. The simplest way is to use a dialog with Get-Credential -Message "MongoDb login"
> New-PSDrive -PSProvider MongoDbGridFs -Name Mongo -Root 'localhost' -Port '27017' -Database 'MyDb' -Collection 'fs.files' -Verify -Credential (Get-Credential -Message "MongoDb login")
The parameters
-Port
and-Collection
don't have to be set (default Port='27017' and Collection='fs').
For listing all existing drive use
> Get-PSDrive -PSProvider MongoDbGridFs
Name Used (GB) Free (GB) Provider Root
---- --------- --------- -------- ----
Mongo MongoDbGridFs localhost
and then removing it
> Remove-PSDrive Mongo
Returns a list of all existing elements in the registred collection. This command gives a quick overview of existings elements and some meta-inforamtions.
Example:
> Get-ChildItem Mongo:
FileName Id UploadDateTime length
-------- -- -------------- ------
testFile 5cd92feb5ba2196a6c5f0da2 13.05.2019 08:50:51 1
Get a specific item from the collection, given by die objectId.
Example:
> Get-Item Mongo:\5cd92feb5ba2196a6c5f0da2
In this way it is easy to store the binary content to a local drive
Example:
> Get-Item Mongo:\5cd92feb5ba2196a6c5f0da2 -Target c:\temp\content.txt
Upload an existing file to the collection.
Example for upload foo.txt to the collection:
> Set-Item Mongo:\foo.txt
Deletes an existing element completely from the collection.
Example:
> Remove-Item Mongo:\123769231768231876
Overwrites the file-name property in the collection of the given element.
Example:
> Rename-Item Mongo:\93097432780089734 -NewName foo2.txt
Get the content of an existing element from the collection.
Example:
> Get-Content Mongo:\93097432780089734
Create a new element in the collection with content of the Value
parameter.
Example:
> Set-Content Mongo: -Name foo3.txt -Value "Test content"
MongoDbGridFsProvider is under the Apache License 2.0.