문제

I am trying to write the following mongodb shell command in powershell:

db.tag.find({$where:"'star wars episode VII'.search(this.name) >= 0"})

So far what I have done is:

$tagCollection = $db["tag"]

$query = @{
    "name" = @{ '$where' = "'star wars episode VII'.search(this['name']) >= 0;" }
}

$cursor = $tagCollection.find([MongoDB.Driver.QueryDocument]$query)

But I'm getting the following error

Exception has been thrown by the target of an invocation.
    + CategoryInfo          : NotSpecified: (:) [], TargetInvocationException
    + FullyQualifiedErrorId : System.Reflection.TargetInvocationException

Any idea/recommendation about what is wrong would be high appreciated

도움이 되었습니까?

해결책

SOLUTION:

$tagCollection = $db["tag"]

$query = @{
    '$where' = "'star wars episode VII'.search(this['name']) >= 0;"
}

$cursor = $tagCollection.find([MongoDB.Driver.QueryDocument]$query)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top