Question

I am trying to make the following mongodb query on powershell:

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

I tried to do the following but doesn't work:

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

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

Any idea, how to do this?

thank you very much

Was it helpful?

Solution

Give this a try:

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

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