Skip to content

Instantly share code, notes, and snippets.

@zippy1981
Created May 20, 2011 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zippy1981/982750 to your computer and use it in GitHub Desktop.
Save zippy1981/982750 to your computer and use it in GitHub Desktop.
Demonstrates a bug in EnsureIndex https://jira.mongodb.org/browse/CSHARP-230
[string] $mongoDriverPath;
# Check to see if we are running the 64 bit version of Powershell.
# See http://stackoverflow.com/questions/2897569/visual-studio-deployment-project-error-when-writing-to-registry
if ([intptr]::size -eq 8) {
$mongoDriverPath = (Get-ItemProperty "HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v3.5\AssemblyFoldersEx\MongoDB CSharpDriver 1.0").'(default)';
}
else {
$mongoDriverPath = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\.NETFramework\v3.5\AssemblyFoldersEx\MongoDB CSharpDriver 1.0").'(default)';
}
Add-Type -Path "$($mongoDriverPath)\MongoDB.Bson.dll";
Add-Type -Path "$($mongoDriverPath)\MongoDB.Driver.dll";
$db = [MongoDB.Driver.MongoDatabase]::Create('mongodb://localhost/NYSThruway');
$collection = $db['RestAreas'];
$collection.Exists() -and $collection.Drop() > $null
$collection.Insert(@{ "title"= "West Nyack (Lot J)"; "location"= ( 41.09968, -73.96232 ) });
# Index it
$indexKeys = (New-Object MongoDB.Driver.Builders.IndexKeysBuilder).GeoSpatial('location');
$collection.EnsureIndex($indexKeys);
# This will only work once
[bool]$exists = $collection.IndexExists($indexKeys);
if ($exists) {
Write-Host "Index Created";
}
else {
Write-Host "Index Was not Created";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment