Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-5036

Array determination bugs

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: 2.24.0
    • Component/s: Operations
    • Labels:
      None
    • Dotnet Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      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": [

      {                         "$eq": ["$some_array._t", "Array"]                     }

      , {
                              "$and": [

      {                                 "$isArray": "$some_array._t"                             }

      ,

      {                                 "$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.

            Assignee:
            boris.dogadov@mongodb.com Boris Dogadov
            Reporter:
            hedgensk@gmail.com Vladislav Ivashnev
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: