سؤال

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