$$NOW can be different in sub-pipelines

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

      Insert any one document in a collection. Run aggregation:

      db.test.aggregate([{$lookup: {as: "out", from: "test", pipeline: [{$project: {_id: 0, now: "$$NOW"}}]}}, {$addFields: {now: "$$NOW"}}])

      Observe the result: 

       [
        {
          _id: ObjectId('69259026e301e10a0d726631'),
          a: 1,
          out: [ { now: ISODate('2025-11-25T11:18:31.095Z') } ],
          now: ISODate('2025-11-25T11:18:31.094Z')
        }
      ] 
      Show
      Insert any one document in a collection. Run aggregation: db.test.aggregate([{$lookup: {as: "out" , from: "test" , pipeline: [{$project: {_id: 0, now: "$$NOW" }}]}}, {$addFields: {now: "$$NOW" }}]) Observe the result:  [   {     _id: ObjectId( '69259026e301e10a0d726631' ),     a: 1,     out: [ { now: ISODate( '2025-11-25T11:18:31.095Z' ) } ],     now: ISODate( '2025-11-25T11:18:31.094Z' )   } ]
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      In an aggregation pipeline, if $$NOW is referenced after a sub-pipeline stage, it can have a different value inside and outside of a sub-pipeline.

            Assignee:
            Mihai Andrei
            Reporter:
            Ivan Fefer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: