Dependency analysis incorrectly requests new field when there is a new document constructed

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Optimization
    • ALL
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Compare these two aggs and their transformBy:

       db.notification.explain(true).aggregate([{ "$match": { "created": { "$gte": { "$date": "2025-02-01T00:00:00Z" }, "$lt": { "$date": "2025-08-01T00:00:00Z" } } } }, {"$addFields":{"xxx": {"$toString": "$created" }}}, { "$group": { "_id": "$xxx"}}])

      Results in

                  transformBy: { created: 1, _id: 0 },
      

      while

       db.notification.explain(true).aggregate([{ "$match": { "created": { "$gte": { "$date": "2025-02-01T00:00:00Z" }, "$lt": { "$date": "2025-08-01T00:00:00Z" } } } }, {"$addFields":{"xxx": {new: {"$toString": "$created" }}}}, { "$group": { "_id": "$xxx"}}])

      Results in

                  transformBy: { created: 1, xxx: 1, _id: 0 },
      

      Moving the `\$toString:"\$existingFIeld" into subdocument caused us to lose track of something and think that `xxx` was somehow a field from the original document...

            Assignee:
            Unassigned
            Reporter:
            Asya Kamsky
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated: