-
Type: Bug
-
Resolution: Fixed
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: None
-
1 - XS (<= 1 day)
-
7188
Goals
<!--- What do you want to achieve? -->
Sort documents by multiple field when using MongoDB collection find or aggregate.
e.g. {$sort: {createdAt: -1, username: 1}}
Expected Results
<!--- What did you expect to happen? -->
First sort by createdAt in descending order and then sort by username in ascending order.
Actual Results
<!--- What happened instead?
e.g. the stack trace of a crash
-->
Since Dictionary in Swift or NSDictionary in Objective-C is unordered collection, the order of {$sort: {createdAt: -1, username: 1}} is uncertain, it could not make sure the consistency of sort order.
For example, using FindOptions for finding document
let options = FindOptions(limit: 20, projection: nil, sort: ["createdAt": -1, "username": 1]) collection.find(filter: ["favorite": "MongoDB Realm"], options: options)
This result will be not consistent, because the result could be sorted by createdAt than username or by username than createdAt.
Steps for others to Reproduce
<!--- What are steps OTHERS can follow to reproduce this issue? -->
Code Sample
<!---
Provide a code sample or test case that highlights the issue.
If relevant, include your model definitions.
For larger code samples, links to external gists/repositories are preferred.
Alternatively share confidentially via mail to help@realm.io.
Full Xcode projects that we can compile ourselves are ideal!
-->
Version of Realm and Tooling
<!---
In the CONTRIBUTING guidelines, you will find a script,
which will help determining some of these versions.
-->
Realm framework version: 10.7.2
Xcode version: 12.4
iOS/OSX version: 14.4
Dependency manager + version: Swift Package Manager