MongoDB
 sql >> Datenbank >  >> NoSQL >> MongoDB

Wie verbinde ich MongoDB mit PowerShell?

Ich weiß, ich bin etwas spät dran, aber ich habe in den letzten Tagen mit Mongodb und Powershell herumgespielt. Die einfachste Lösung, die ich gefunden habe, ist die Installation der MongoDB-Cmdlets aus der Powershell-Galerie:

https://github.com/nightroman/Mdbc

Schritt 1:Holen und installieren.

Mdbc wird als PowerShell Gallery-Modul Mdbc vertrieben. In PowerShell 5.0 oder mit PowerShellGet können Sie es mit diesem Befehl installieren:

Install-Module Mdbc 

Schritt 2:Importieren Sie in einer PowerShell-Eingabeaufforderung das Modul:

Import-Module Mdbc 

Schritt 3:Sehen Sie sich die Hilfe an:

help about_Mdbc 
help Connect-Mdbc -full

Führen Sie dann die folgenden Schritte aus, um zu sehen, ob die Einrichtung funktioniert:

# 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