Uploaded image for project: 'SlamData'
  1. SD-1038

GROUP BY on array field fails with "can't use an array for _id"

    Details

    • Type: Bug
    • Status: Done
    • Priority: Medium
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.3
    • Component/s: Community, Quasar
    • Labels:
    • Environment:

      v2.2.0 Linux distribution with Chrome client

      Description

      Working with the following sample Collection:

      {
          "_id" : 1,
          "name" : "record-1",
          "associations" : [ 
              {
                  "role" : "student",
                  "associationStatus" : "active"
              }, 
              {
                  "role" : "teacher",
                  "associationStatus" : "active"
              }
          ]
      }
      {
          "_id" : 2,
          "name" : "record-2",
          "associations" : [ 
              {
                  "role" : "student",
                  "associationStatus" : "active"
              }, 
              {
                  "role" : "teacher",
                  "associationStatus" : "inactive"
              }
          ]
      }
      {
          "_id" : 3,
          "name" : "record-1",
          "associations" : [ 
              {
                  "role" : "student",
                  "associationStatus" : "active"
              }
          ]
      }
      

      The following query results in an exception:

      SELECT associations.role, count(*) AS Count
      FROM "/Dev/slamdata-sandbox/hasArray"
      GROUP BY associations.role
      

      The error is:

      Error in query: Command failed with error 16996: 'exception: insert for $out failed: { lastOp: Timestamp 1443556317000|1, connectionId: 44, err: "can't use an array for _id", code: 2, n: 0, ok: 1.0 }' on server localhost:27017. The full response is { "errmsg" : "exception: insert for $out failed: { lastOp: Timestamp 1443556317000|1, connectionId: 44, err: \"can't use an array for _id\", code: 2, n: 0, ok: 1.0 }", "code" : 16996, "ok" : 0.0 }
      

      The workaround I've found is to include {no-op in the GROUP BY. So, the following works, but hopefully isn't considered a long term solution:

      SELECT associations.role, count(*) AS Count
      FROM "/Dev/slamdata-sandbox/hasArray"
      GROUP BY no-op, associations.role
      

        Attachments

          Activity

            People

            • Assignee:
              greg Greg Pfeil
              Reporter:
              pjaffe Peter Jaffe
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: