Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Mdbc module - MongoDB cmdlets for PowerShell

build

latest commit 2cd666027e
Roman Kuzmin authored April 17, 2014
Octocat-spinner-32 About v4.4.4 Dictionary : IConvertibleToBsonDocument December 02, 2013
Octocat-spinner-32 Module build April 17, 2014
Octocat-spinner-32 Scripts Minor changes February 22, 2014
Octocat-spinner-32 Src build April 17, 2014
Octocat-spinner-32 Tests v4.7.0 April 05, 2014
Octocat-spinner-32 .build.ps1 build April 17, 2014
Octocat-spinner-32 .gitignore build April 17, 2014
Octocat-spinner-32 Download.ps1 Download November 15, 2013
Octocat-spinner-32 LICENSE.txt Mongo v2.6-rc0, driver v1.9-rc0 February 28, 2014
Octocat-spinner-32 README.md 4.5.0 Data files in JSON format December 08, 2013
Octocat-spinner-32 Release-Notes.md v4.7.0 April 05, 2014
README.md

Mdbc module - MongoDB Cmdlets for PowerShell

Mdbc is the Windows PowerShell module based on the official MongoDB C# driver. Mdbc makes MongoDB scripting in PowerShell easier and provides some extra features like bson/json file collections which do not even require MongoDB.

Quick Start

Step 1: Get and install. Mdbc is distributed as the NuGet package Mdbc. Download it to the current location as the directory "Mdbc" by this PowerShell command:

Invoke-Expression (New-Object Net.WebClient).DownloadString('https://raw.github.com/nightroman/Mdbc/master/Download.ps1')

Alternatively, download it by NuGet tools or directly. In the latter case rename the package to ".zip" and unzip. Use the package subdirectory "tools/Mdbc".

Copy the directory Mdbc to a PowerShell module directory, see $env:PSModulePath, normally like this:

C:/Users/<User>/Documents/WindowsPowerShell/Modules/Mdbc

Step 2: In a PowerShell command prompt import the module:

Import-Module Mdbc

Step 3: Take a look at help:

help about_Mdbc
help Connect-Mdbc -full
...

Step 4: Invoke these operations line by line, reading the comments (make sure that mongod is started, otherwise Connect-Mdbc fails):

# Load the module
Import-Module Mdbc

# Connect the new collection test.test
Connect-Mdbc . test test -NewCollection

# Add some test data
@{_id=1; value=42}, @{_id=2; value=3.14} | Add-MdbcData

# Get all data as custom objects and show them in a table
Get-MdbcData -As PS | Format-Table -AutoSize | Out-String

# Query a document by _id using a query expression
$data = Get-MdbcData (New-MdbcQuery _id -EQ 1)
$data

# Update the document, set the 'value' to 100
$data._id | Update-MdbcData (New-MdbcUpdate -Set @{value = 100})

# Query the document using a simple _id query
Get-MdbcData $data._id

# Remove the document
$data._id | Remove-MdbcData

# Count remaining documents, 1 is expected
Get-MdbcData -Count

If the code above works then the module is installed and ready to use.

Next Steps

Read cmdlet help topics and take a look at their examples, they show some basic use cases to start with.

Take a look at scripts in the directory Scripts, especially the interactive profile Mdbc.ps1. Other scripts are rather toys but may be useful. Even more examples can be found in the directory Tests of the project repository.

Mdbc cmdlets are designed for rather simple jobs. For advanced operations the C# driver API should be used directly. Some API was specifically designed with PowerShell in mind. See the C# driver manuals.

Something went wrong with that request. Please try again.