Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mockfirestore/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def stream(self, transaction=None) -> Iterator[DocumentSnapshot]:
doc_snapshots = self._query_filter(doc_snapshots, self._field_filter)

if self.orders:
for key, direction in self.orders:
for key, direction in reversed(self.orders): # Process least significant first
doc_snapshots = sorted(
doc_snapshots,
key=lambda doc: doc.to_dict()[key],
Expand Down
22 changes: 22 additions & 0 deletions tests/test_collection_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,28 @@ def test_collection_orderBy_descending(self):
self.assertEqual({'order': 2}, docs[1].to_dict())
self.assertEqual({'order': 1}, docs[2].to_dict())

def test_collection_orderBy_multiple(self):
fs = MockFirestore()
doc1 = {'order': 2, 'another_order': 100}
doc2 = {'order': 1, 'another_order': 200}
doc3 = {'order': 1, 'another_order': 1}
doc4 = {'order': 3, 'another_order': 3}
doc5 = {'order': 3, 'another_order': 2}
fs._data = {'foo': {
'first': doc1,
'second': doc2,
'third': doc3,
'fourth': doc4,
'fifth': doc5
}}

docs = list(fs.collection('foo').order_by('order').order_by('another_order', direction="DESCENDING").stream())
self.assertEqual(doc2, docs[0].to_dict())
self.assertEqual(doc3, docs[1].to_dict())
self.assertEqual(doc1, docs[2].to_dict())
self.assertEqual(doc4, docs[3].to_dict())
self.assertEqual(doc5, docs[4].to_dict())

def test_collection_limit(self):
fs = MockFirestore()
fs._data = {'foo': {
Expand Down