nightroman / Mdbc

MongoDB Cmdlets for PowerShell
Apache License 2.0
141 stars 16 forks source link

Trying to query using $nin and $regex #83

Closed yvesgermain closed 1 year ago

yvesgermain commented 1 year ago

I'm trying to do a query where I don't want any IdentityReference that starts with either the string "Domain\" or "AUTORITE NT\". This is what I tried. How should this query be structured? Get-mdbcdata -Filter @{ "IdentityReference" = @{'$nin' = @( @{'$regex' = 'Domain\'}, @{'$regex' = 'AUTORITE NT\'} )} }

yvesgermain commented 1 year ago

The error message is :Get-MdbcData: Command find failed: cannot nest $ under $in.

nightroman commented 1 year ago

I think this error is expected -- https://www.mongodb.com/docs/manual/reference/operator/query/in/#use-the--in-operator-with-a-regular-expression

You cannot use $regex operator expressions inside an $in.

Try to recompose the expression using something like ~ $not with $regex and pattern Domain\\|AUTORITE NT\\.

yvesgermain commented 1 year ago

This worked: Get-MdbcData -Filter @{ '$nor' = @(@{ "IdentityReference" = @{'$regex' = '^Domain\\'}}, @{"IdentityReference" = @{'$regex' = '^AUTORITE NT\\'}})}