sql >> Database >  >> NoSQL >> MongoDB

Powershell Mongodb-authenticatie

Hier is een fragment van MongoDb-authenticatie van Powershell.

Ik gebruik hier MongoDB C#-stuurprogramma (kijk hier )

# 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:[email protected]"
$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
}



  1. Groeperen en tellen met behulp van aggregatieframework

  2. NodeJS - MongoClient.Verbinden met URL naar DB anders dan standaard

  3. Redis publiceren-abonneren:levert Redis gegarandeerd de boodschap af, zelfs onder enorme stress?

  4. MongoDB:output 'id' in plaats van '_id'