小编Dha*_*n M的帖子

如何使用PowerShell连接MongoDB?

我已经尝试过以下代码:

$mongoDbDriverPath = '
 C:\Mongodb\net45\'
$mongoServer = 'localhost:27017'

Add-Type -Path "$($mongoDbDriverPath)MongoDB.Bson.dll"
Add-Type -Path "$($mongoDbDriverPath)MongoDB.Driver.dll"
$databaseName = "test"
$collectionName = "sample"
$client = New-Object -TypeName MongoDB.Driver.MongoClient -ArgumentList "mongodb://localhost:27017"
$server = $client.GetServer()
$database = $server.GetDatabase($databaseName)
$collection = $database.GetCollection($collectionName)
Write-Host $server,$database,$collection
$query = [MongoDB.Driver.Builders.Query]::EQ("Name", "sample")

$results = $collection.Find($query)
$results
Run Code Online (Sandbox Code Playgroud)

但它显示了一些错误:

New-Object:使用“1”个参数调用“.ctor”时出现异常:“无法加载文件或程序集'System.Runtime.InteropServices.RuntimeInformation,Version=4.0.0.0,`Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a'或其依赖项之一。系统找不到指定的文件。”
在 D:\Users\xxxxxx\Desktop\Mongodb With Powershell\task1.ps1:8 char:11

我该如何克服这个错误?

powershell mongodb

8
推荐指数
2
解决办法
3万
查看次数

标签 统计

mongodb ×1

powershell ×1