Uploaded image for project: 'Realm JavaScript SDK'
  1. Realm JavaScript SDK
  2. RJS-253

Document sorted() better

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None

      See this issue for details: https://github.com/realm/realm-js/issues/306

      > Flash forward a year later and I stumbled on the same problem. The Realm JS documentation should have mentioned in more details on how to sort properly in reverse order.
      In order to perform sorting in reverse order, the .sorted() method should be invoked via fluent API chaining without intermediary variable assignment
      Improper reverse sorting:
      let items = realm.objects('Article').filtered('createdAt > $0', twoDaysAgo);
      const reverseSortedItems = items.sorted('createdAt', true); //will not work
      console.log(reverseSortedItems);
      Proper reverse sorting:
      const sortedItems = realm.objects('Article').filtered('createdAt > $0', twoDaysAgo).sorted('createdAt', true); //sorted in reverse order by date
      console.log(sortedItems)

            Assignee:
            Unassigned Unassigned
            Reporter:
            brian.munkholm@mongodb.com Brian Munkholm (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: