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

Support expressions in $densify range bounds

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • None
    • Environment:
      Using mongodb-org-6.0.0-0.1.latest.el7.x86_64 on CentOS 7
    • ALL

      The $densify aggregation pipeline stage seems unable to evaluate range bounds expressions, requiring the range bounds to be constant.

       

      See the following example (the collection testcoll contains a single documents with only the _id field):

      sometestdb> db.testcoll.aggregate([{$addFields: {a: 1}}, {$densify: {field: "a", range: {bounds: [0, 5], step: 1}}}])
      [
        { a: 0 },
        { _id: ObjectId("6284a16d64553eaf74b1e189"), a: 1 },
        { a: 2 },
        { a: 3 },
        { a: 4 }
      ]
      
      sometestdb> db.testcoll.aggregate([{$addFields: {a: 1}}, {$densify: {field: "a", range: {bounds: [{$toInt: "0"}, 5], step: 1}}}])
      MongoServerError: A bounding array must be an ascending array of either two dates or two numbers
       

      The first aggregate() call gives the correct result, and I'd expect the second one to evaluate the $toInt and yield the same result. Of course $toInt isn't a particularly useful use case but there are indeed useful computations which an user may want to do on the range bounds; for example, when using dates, one may want to truncate the start and end date to the hour or to the day before they are used for the densify operation.

            Assignee:
            Unassigned Unassigned
            Reporter:
            gianluca.nitti@voismart.it Gianluca Nitti
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: