문제

* 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

도움이 되었습니까?

해결책

It's just like the keys. Don't create a document if you are using the helpers.

$options = [MongoDB.Driver.Builders.IndexOptions]::SetUnique(true)

다른 팁

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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top