• Stars
    star
    139
  • Rank 262,954 (Top 6 %)
  • Language
    PowerShell
  • License
    Apache License 2.0
  • Created about 13 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

MongoDB Cmdlets for PowerShell

NuGet PSGallery

Mdbc

MongoDB Cmdlets for PowerShell


Mdbc is the PowerShell module based on the official MongoDB C# driver. Mdbc makes MongoDB data and operations PowerShell friendly.

  • The PSGallery package is for PowerShell Core and PowerShell v5.1 .NET 4.7.2
  • The NuGet package is for PowerShell v3-v5.1, .NET 4.7.2

Quick start

Step 1: Get and install

Package from PSGallery

Mdbc for PowerShell Core and v5.1 is published as the PSGallery module Mdbc.

You can install the module by this command:

Install-Module Mdbc

Package from NuGet

Mdbc for PowerShell v3-v5.1 is published as the NuGet package Mdbc. Download it by NuGet tools or directly. In the latter case save it as ".zip" and unzip. Use the package subdirectory "tools/Mdbc".

Copy the directory Mdbc to one of the PowerShell module directories, see $env:PSModulePath, for example 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 and available commands:

help about_Mdbc
help Connect-Mdbc -Full
Get-Command -Module Mdbc

Step 4: Make sure mongod is running and try some commands:

# Load the module
Import-Module Mdbc

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

# Add two documents
@{_id = 1; value = 42}, @{_id = 2; value = 3.14} | Add-MdbcData

# Get documents as PS objects
Get-MdbcData -As PS | Format-Table

# Get the document by _id
Get-MdbcData @{_id = 1}

# Update the document, set 'value' to 100
Update-MdbcData @{_id = 1} @{'$set' = @{value = 100}}

# Get the document again, 'value' is 100
$doc = Get-MdbcData @{_id = 1}

# Remove the document
$doc | Remove-MdbcData

# Count documents, 1
Get-MdbcData -Count

Next Steps

Read cmdlet help topics and take a look at examples for some basic use cases.

Use Scripts/Mdbc.ArgumentCompleters.ps1 for database and collection name completion and property completion. Scripts/Update-MongoFiles.ps1 is a toy for making test data but may be useful for tracking file changes. See also tests, for example:

Driver methods and module commands

Driver Module Output
Client
MongoClient Connect-Mdbc $Client $Database $Collection
GetDatabase Get-MdbcDatabase database(s)
DropDatabase Remove-MdbcDatabase none
Transactions Use-MdbcTransaction -
Watch Watch-MdbcChange -Client cursor
Database
RunCommand Invoke-MdbcCommand document
GetCollection Get-MdbcCollection collection(s)
CreateCollection Add-MdbcCollection none
RenameCollection Rename-MdbcCollection none
DropCollection Remove-MdbcCollection none
Watch Watch-MdbcChange -Database cursor
Collection
InsertOne Add-MdbcData none
Find Get-MdbcData documents
CountDocuments Get-MdbcData -Count count
Distinct Get-MdbcData -Distinct values
FindOneAndDelete Get-MdbcData -Remove old document
FindOneAndReplace Get-MdbcData -Set old or new document
FindOneAndUpdate Get-MdbcData -Update old or new document
DeleteOne Remove-MdbcData none or info (-Result)
DeleteMany Remove-MdbcData -Many none or info (-Result)
ReplaceOne Set-MdbcData none or info (-Result)
UpdateOne Update-MdbcData none or info (-Result)
UpdateMany Update-MdbcData -Many none or info (-Result)
Aggregate Invoke-MdbcAggregate documents
Watch Watch-MdbcChange -Collection cursor

See also

More Repositories

1

Invoke-Build

Build Automation in PowerShell
PowerShell
638
star
2

PowerShellTraps

Collection of PowerShell traps and oddities
PowerShell
432
star
3

FarNet

Far Manager framework for .NET modules and scripts in PowerShell, F#, JavaScript.
C#
134
star
4

SplitPipeline

Parallel Data Processing in PowerShell
PowerShell
124
star
5

PowerShelf

PowerShell Script Tools
PowerShell
118
star
6

Helps

PowerShell Help Builder
PowerShell
43
star
7

PS-GuiCompletion

A graphical menu for PowerShell tab completions.
PowerShell
42
star
8

PsdKit

PowerShell data (psd1) tool kit
PowerShell
42
star
9

Ldbc

LiteDB Cmdlets, the document store in PowerShell
PowerShell
40
star
10

FarNet.FSharp.PowerShell

F# friendly PowerShell Core helper
F#
20
star
11

Xmlips

XML in PowerShell
PowerShell
14
star
12

Invoke-Build.template

Invoke-Build script template
PowerShell
5
star
13

BsonFile

BSON/JSON file collections in MongoDB, PowerShell module
PowerShell
5
star
14

FarLite

PowerShell module with LiteDB browser in Far Manager
PowerShell
3
star
15

FarDescription

Far Manager style descriptions of files and directories
C#
3
star
16

ClearScript

ClearScript and FarNet lab for Far Manager scripting in JavaScript
PowerShell
2
star
17

FarMongo

PowerShell module with MongoDB browser in Far Manager
PowerShell
2
star
18

FarGit

Deprecated and replaced by https://github.com/nightroman/FarNet/tree/main/GitKit
PowerShell
1
star
19

FarNet.FSharp.Data

FSharp.Data package for FarNet.FSharpFar
PowerShell
1
star
20

FarNet.FSharp.Charting

FarNet friendly FSharp.Charting extension
F#
1
star
21

FarNet.template

FarNet module and script template
PowerShell
1
star
22

FarNet.Redis

StackExchange.Redis PowerShell module and FarNet library
C#
1
star
23

FarNet.Stateless

Interactive workflows using dotnet-state-machine/stateless, PowerShell module and FarNet library
C#
1
star