The Realm JavaScript documentation says:
Sorting and find distinct values are possible with functions SORT and DISTINCT, e.g. age > 20 SORT(name ASC, age DESC) DISTINCT(name)
.
I'm trying to use it like this:
realm
.objects<CardFace>(CardFaceSchema)
.filtered(`SORT(name ASC, expansion.releaseDate DESC) DISTINCT(name)`)
And get the red screen of death with the following message: SORT(name ASC, expansion.releaseDate DESC) DISTINCT(name):1:4(4): Invalid predicate.
What am I doing wrong? My realm version is 2.3.3
We are hoping you have read our previous post on Local Database in React Native App. A realm is an open-source object database management system, initially for mobile, also available for platforms such as Xamarin or React Native, and others, including desktop applications, and is licensed under the Apache License.
Getting started with React Native will help you to know more about the way you can make a React Native project. We are going to use react-native init to make our React Native App. Assuming that you have node installed, you can use npm to install the react-native-cli command line utility.
If data consist of name and id as attributes then we should be able to sort data with alphabetical order of name or we can also sort according to the increasing or decreasing value of Id. In React it is easy to sort things because of the sort function.
A realm is an open-source object database management system, initially for mobile, also available for platforms such as Xamarin or React Native, and others, including desktop applications, and is licensed under the Apache License. We can perform all the CRUD transactions in this database and much faster than the SQLite database.
Sort and Distinct can't be applied without a predicate. So modify your filter to:
realm
.objects<CardFace>(CardFaceSchema)
.filtered(`TRUEPREDICATE SORT(name ASC, expansion.releaseDate DESC) DISTINCT(name)`)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With