Created
May 20, 2011 11:27
-
-
Save zippy1981/982750 to your computer and use it in GitHub Desktop.
Demonstrates a bug in EnsureIndex https://jira.mongodb.org/browse/CSHARP-230
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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