It's just like the keys. Don't create a document if you are using the helpers.
$options = [MongoDB.Driver.Builders.IndexOptions]::SetUnique(true)
Pergunta
* EDITED * could someone please help me creating an index in mongodb using powershell?
I am following this create index using c# driver
this is my code:
$keys = IndexKeys.Ascending("Message Subject", "Job Result").Descending("Time Stamp")
$options = new-object MongoDB.Driver.IndexOptionsDocument
$options.SetUnique(true)
$notificationCollectionByDate.CreateIndex(keys, options)
I got the following errors
Method invocation failed because [MongoDB.Driver.IndexOptionsDocument] doesn't contain a method named 'SetUnique'.
The term 'IndexKeys.Ascending' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and tr y again.
Any idea what is wrong with my code?
thank you very much
Solução
It's just like the keys. Don't create a document if you are using the helpers.
$options = [MongoDB.Driver.Builders.IndexOptions]::SetUnique(true)
Outras dicas
thanks Craig you gave me the clue to get the answer:
this is the solution:
$keys = [MongoDB.Driver.Builders.IndexKeys]
$keys = [MongoDB.Driver.Builders.IndexKeys]::Ascending("Message Subject", "Job Result")
$keys = [MongoDB.Driver.Builders.IndexKeys]::Descending("Time Stamp")
$options = [MongoDB.Driver.Builders.IndexOptions]::SetUnique($true)
$options = [MongoDB.Driver.Builders.IndexOptions]::SetDropDups($true)
$notificationCollectionByDate.CreateIndex($keys, $options)