Question

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

Was it helpful?

Solution

SOLUTION:

$tagCollection = $db["tag"]

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

$cursor = $tagCollection.find([MongoDB.Driver.QueryDocument]$query)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top