Answer the question
In order to leave comments, you need to log in
How to get sorted data from the database in sails?
More precisely, I know how to get it, but how to get sorted data without regard to case?
In mongo, this is done like this:
db.getCollection('myCollection').aggregate([
{ "$project": {
"name": 1,
"insensitive": { "$toLower": "$name" }
}},
{ "$sort": { "insensitive": 1 } }
])
var param = {
name: { 'contains': search.id },
text: { 'contains': search.text },
summary: { 'contains': search.summary },
limit: limit,
skip: skip,
sort: sort
};
var cursor = News.find(param).populateAll();
cursor.exec(function (err, n) {
if (err) {
console.log(err);
}
News.count(param).exec(function (error, count) {
next({ data: n, total: count });
});
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question