$type projection operator (cast types within aggregation pipelines).

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Duplicate
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • Fully Compatible
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Currently there is no way to convert types without the aggregation framework.

      This would be useful to allow things like Dates <-> Timestamps/Strings, Strings <-> Numbers and even cooler stuff like OID <-> String.

      I think the most intuitive way to add type casting would be to reuse the $type query in the $project stage of the aggregation pipeline which would maybe look something like this:

      db.col.aggregate([{
      	$project: {
      		my_date: { $type: ["$my_date", 16] }
      	}
      }])
      

      Where "$my_date" is currently a `Date` bson type and will be casted to a 32-bit integer (16).

      Perhaps aliases could also be supported to allow for:

      db.col.aggregate([{
      	$project: {
      		my_date: { $type: ["$my_date","int"] }
      	}
      }])
      

      Ultimately syntax doesn't matter but I think type casting is something the aggregation framework is lacking which would help many use cases without relying on in app implementations.

              Assignee:
              Unassigned
              Reporter:
              Dylan Piercey
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

                Created:
                Updated:
                Resolved: