Assuming that there is no index, is there a significant performance difference between sorting based on just one field vs multiple fields?
db.movies.aggregate([
{ $sort: { likes: -1 } }
{ $limit: 100 }
])
vs
db.movies.aggregate([
{ $sort: { likes: -1,
views: -1,
comments: -1,
bookmarked: -1 ,
dislikes: 1
}
},
{ $limit: 100 }
])
If I am building an APP, will the second query scale? Would there be a significant increase in time cost
In an oversimplified way, it depends on
a) How much memory do you have on your computer
b) How big is your dataset - will it hold in memory
If it does, then the performance difference will be so insignificant that you will not detect it practically.
If it does not, you have to read from disk and possibly use swap on your computer, and then the difference will be significant.