从powershell搜索mongodb中的子字符串

时间:2014-05-10 08:56:26

标签: mongodb powershell mongodb-.net-driver mongodb-query

我正在尝试在powershell上进行以下mongodb查询:

collection.find({"field1":"valueA","field2":"valueB","field3":/subStr_ValueC/})

我尝试执行以下操作但不起作用:

$query = @{
            "field1" = $notification["A"]
            "field2" = $notification["B"]
            "field3" = "/" + $notification["C"] + "/"
        }

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

任何想法,怎么做?

非常感谢

1 个答案:

答案 0 :(得分:2)

尝试一下:

$query = @{
  'field1' = $notification['A']
  'field2' = $notification['B']
  'field3' = @{ '$regex' = '.*' + $notification['C'] + '.*'; '$options' = 'i' }
}

$cursor = $collection.find([MongoDB.Driver.QueryDocument]$query)
相关问题