Hi,
Here's my schema:"++id,from,to,type,time,msg", I would like to query the latest several messages which 'from' or 'to' equals to a value, and the following phrase I got works:
db.Msg
.where('from')
.equals(id)
.or('to')
.equals(id)
.sortBy("time", function(array) {
deferred.resolve(array.slice(-limit));
})
But I think this is not the best choice, could you give me some advice. Thanks
I would recommend using
db.table.orderBy('time').and(x => x.from===id || x.to===id).reverse().limit(limit).toArray()
You then don't have to query the entire result and sort it in memory and the query would perform equally no matter how large the table would grow.
Yeah, quit helpful, thanks!
Most helpful comment
I would recommend using
You then don't have to query the entire result and sort it in memory and the query would perform equally no matter how large the table would grow.