-
Type: Bug
-
Resolution: Works as Designed
-
Priority: Unknown
-
None
-
Affects Version/s: 2.24.0
-
Component/s: Operations
-
None
-
Dotnet Drivers
Summary
- MongoDB version 7.0.6
- MongoDB.Driver version 2.24
`is Array` condition translates in query string that doesn't work correct. Those string returns false when it must return true.
!=null check is working by itself to determine if field is set. But when we use it in combined condition for array:
array!=null && array.Contains(`some_value`); in GroupBy method it leads to exception
How to Reproduce
I made a simple project that demonstrates few cases. Please find attached project below
Additional Background
I have a collection of documents that represents entity called Sirena in my program. And I needed to write the request that counts several parameters. Some of those fields are array, but In some documents this field is missing. As a result I faced the problem when I was trying to write a request to db.
I also posted a question on stackoverflow, I'm not sure if it may be useful, because attached project very carefully demonstrates the problems. One of users adviced me to use construction (array ?? long[]).Contains and it works. But I expect that `is Array` and `!=null` have to be translated to json query correct.
The `is Array` condition translates to query string as:
```js
"$cond": {
"if": {
"$and": [{
"$or": [
, {
"$and": [
,
{ "$in": ["Array", "$some_array._t"] }...
```
Unfortunately, if `some_array` field is array, condition `{"$eq": ["$some_array._t", "Array"]}` returns false. If we change it to `{"$isArray": "$some_array"}`, then it will works for array field. But as I see the second statement in 'or' condition has to work with field when it has several types. I don't know how to fix it.