Reputation:
I have numeric data each in every document... I am getting the data using this code
db.collection('Stations').orderBy("station","asc").onSnapshot((querySnapshot) =>{
this.setState({
stations:querySnapshot.docs.map(doc => {
return {
id: doc.id,
station:doc.data().station
}
})
})
});
And the data is not getting arranged properly as seen below:
Upvotes: 2
Views: 1260
Reputation: 598901
You're ordering by string values, which use lexicographical ordering. And in lexicographical order "100"
comes before "2"
.
To fix your problem, have a field with only the numerical value, and order by that field. Alternatively pad the numbers so they all have the same length, because "002"
comes before "100
".
Also see:
Upvotes: 3