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

sort not working on projection created fields in find

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 4.4.0-rc14
    • Component/s: None
    • Labels:
    • 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 })

      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-server-query Backlog - Query Team (Inactive)
            Reporter:
            cherviakov.ivan@gmail.com Ivan Cherviakov
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: