Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell Mongodb身份验证_Mongodb_Powershell_Database Connection_Driver - Fatal编程技术网

Powershell Mongodb身份验证

Powershell Mongodb身份验证,mongodb,powershell,database-connection,driver,Mongodb,Powershell,Database Connection,Driver,谁能告诉我如何使用power shell将mongodb与身份验证连接起来?我看到了本地主机连接的引用,但没有看到mongodb服务器连接字符串 欢迎任何参考这里是Powershell的MongoDb身份验证片段 我在这里使用MongoDB C#驱动程序(看看) 我假设这不适用于最新的MongoDB驱动程序,因为我在关于get collection的几乎相同的脚本中遇到了相同的问题。您能否为最新的驱动程序提供解决方案?因为它实际上也解决了我的悬赏问题。这是我的问题,与此类似,但我需要最新的C#驱

谁能告诉我如何使用power shell将mongodb与身份验证连接起来?我看到了本地主机连接的引用,但没有看到mongodb服务器连接字符串


欢迎任何参考

这里是Powershell的MongoDb身份验证片段

我在这里使用MongoDB C#驱动程序(看看)


我假设这不适用于最新的MongoDB驱动程序,因为我在关于get collection的几乎相同的脚本中遇到了相同的问题。您能否为最新的驱动程序提供解决方案?因为它实际上也解决了我的悬赏问题。这是我的问题,与此类似,但我需要最新的C#驱动程序:我也有它与最新的驱动程序,但我现在还没有与我的代码片段。如果你稍后发布它,那就太好了
# Mongo DB driver
Add-Type -Path 'C:\Path_To_mongocsharpdriver\mongocsharpdriver.1.9.2\lib\net35\MongoDB.Bson.dll'
Add-Type -Path 'C:\Path_To_mongocsharpdriver\mongocsharpdriver.1.9.2\lib\net35\MongoDB.Driver.dll'

# Connexion to MongoDB
$connectionString = "mongodb://user1:password1@localhost"
$db =  "MyDBName"
$collection =  "MyCollectionName"

function Get-MongoDBCollection ($connectionString, $db, $collection)
{
  $mongoClient = New-Object MongoDB.Driver.MongoClient($connectionString)
  $mongoServer = $mongoClient.GetServer()
  $mongoDatabase = $mongoServer.GetDatabase($db)
  $mongoCollection = $mongoDatabase.GetCollection($collection)
  return $mongoCollection
}

$FileName = $args[0]
# get the file name 
$FileNameLeaf = Split-Path $FileName -Leaf

# Connect to MongoDB and get collection
$mongoCollection = Get-MongoDBCollection $connectionString $db $collection

# Verify if this file is integrated
$query = New-Object MongoDB.Driver.QueryDocument('Fic_Data', $FileNameLeaf)
$found = $mongoCollection.FindOne($query)
if ($found -ne $null)
{
  Write-Host "`tThe file $FileNameLeaf is integrated !"
  return
}