我正在尝试在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)
任何想法,怎么做?
非常感谢
答案 0 :(得分:2)
尝试一下:
$query = @{
'field1' = $notification['A']
'field2' = $notification['B']
'field3' = @{ '$regex' = '.*' + $notification['C'] + '.*'; '$options' = 'i' }
}
$cursor = $collection.find([MongoDB.Driver.QueryDocument]$query)