add $throw/$error as pipeline operator

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • None
    • Query Optimization
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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"
            ]
          }
        }
      }

            Assignee:
            [DO NOT USE] Backlog - Query Optimization
            Reporter:
            Adinoyi Omuya (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated: