I use Meteorwith Reactand react-meteor-data. I am trying to get a function Videos.find(...)to return an array sorted by 'index' field. See my code below.
The first console.log()prints an array that is correctly sorted. The second console.log()prints an array by default. Even if I changed the sort option, it seems to be ignored. I canβt figure out how to sort the constant videos.
export default DashboardContainer = createContainer(props => {
const videosHandle = Meteor.subscribe('userVideos');
const loading = !videosHandle.ready();
const videos = !loading ? Videos.find({}, {fields: {title:1, subtitle:1,
duration:1, thumb:1, url:1, index:1, groups:1}, sort: {index:1}}).fetch() : [];
console.log(Videos.find({}, {fields: {title:1, subtitle:1, duration:1, thumb:1, url:1, index:1, groups:1}, sort: {index:1}}).fetch());
console.log(videos);
return {
loading,
videos,
};
}, Dashboard);
Update:
If I use console.log(videos.map((i) => i.index));instead console.log(videos), I get a list printed in the correct order:
[1,2,3,4,5...]
Why?
source
share