sort not working on projection created fields in find

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Works as Designed
    • Priority: Major - P3
    • None
    • Affects Version/s: 4.4.0-rc14
    • Component/s: None
    • Query
    • ALL
    • Hide
      db.collection.find({ userId: 'userId', startDate: { $gt: ISODate("2020-07-01") } }, { time: { $divide: [{ $subtract: ['$endDate', '$startDate']  }, 3600000] } }).sort({ time: -1 })
      
      Show
      db.collection.find({ userId: 'userId', startDate: { $gt: ISODate("2020-07-01") } }, { time: { $divide: [{ $subtract: ['$endDate', '$startDate'] }, 3600000] } }).sort({ time: -1 })
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      Given query in mongodb shell:

      db.collection.find({ userId: 'userId', startDate: { $gt: ISODate("2020-07-01") } }, { time: { $divide: [{ $subtract: ['$endDate', '$startDate']  }, 3600000] } }).sort({ time: -1 })
      

      sort does not affect result, always get the same no matter use

      sort({ time: 1})

      or

      sort({ time -1 })

            Assignee:
            Backlog - Query Team (Inactive)
            Reporter:
            Ivan Cherviakov
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: