Hello friends I am writing the web service using sails js. I am fetching all posts and getting the following response :
[
{
id: "559458c51ccc9c716dabf666",
comments : [],
liked : {
data : [
{
id: "559458c51eee9c716dabf666",
username : "abc"
},
{
id: "559458c51eee9c716dabf111",
username : "xyz"
}
],
count : 2
}
},
{
id: "559458c51ccc9c716dabf666",
comments : [],
liked : {
data : [
{
id: "559458c51eee9c716dabf666",
username : "abc"
},
{
id: "559458c51eee9c716dabf666",
username : "pqr"
},
{
id: "559458c51eee9c716dabf111",
username : "xyz"
}
],
count : 3
}
}
]
I want to sort above records using the count of liked posts. In above response we are getting liked count as liked { data : [], count : 2}
.
I am doing like this :
getPost: function(callback) {
Posts.find().sort('liked.count desc').populateAll().exec( function (err, posts) {
if(err) {
return callback({error:err, code:500});
}
if (posts) {
callback(null,posts);
}
});
}
What to do to sort the posts using the count
which is in the liked : {}