Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-27190

add $throw/$error as pipeline operator

    XMLWordPrintableJSON

Details

    • Icon: New Feature New Feature
    • Resolution: Unresolved
    • Icon: Major - P3 Major - P3
    • None
    • None
    • Aggregation Framework
    • None
    • Query Optimization

    Description

      There are cases where MongoDB's behavior is inconsistent with a user's expectation and in such cases, it would be helpful if the user could force the aggregation framework to return an error - instead of having operations proceed.

      An example is the power function:

      db.xy.aggregate({"$project":{"pow":{ "$pow": [ -2, 4.4 ] }}})
      {
        "result": [
          {
            "_id": ObjectId("56d4699e3a0b52029321e0d5"),
            "pow": NaN
          },
        ],
        "ok": 1
      }

      Other relational databases - e.g. MySQL - return an error:

      ERROR 1690 (22003): DOUBLE value is out of range in 'pow(-(2),-(4.4))'

      It would be helpful if I could write something like:

      {
        "$project": {
          "pow": {
            "$cond": [
              {
                "$eq": [
                  {
                    "$pow": [
                      -2,
                      4.4
                    ]
                  },
                  NaN
                ]
              },
              {
                "$throw": "invalid operation"
              },
              "good"
            ]
          }
        }
      }

      Attachments

        Activity

          People

            backlog-query-optimization Backlog - Query Optimization
            adinoyi.omuya@mongodb.com Adinoyi Omuya
            Votes:
            0 Vote for this issue
            Watchers:
            13 Start watching this issue

            Dates

              Created:
              Updated: