Saturday, 24 August 2013

Count subquery in a select - mongoDB

Count subquery in a select - mongoDB

I want to make a query to get a kind of ranking of users with more tweets
in my database mongoDB:
var TeewtSchema = new Schema({
userId: Number,
twweetId : Number,
createdAt: Date,
cuerpo: String,
nameUser: String,
location: String,
avatar: String,
user: String
});
MySql that output something similar to:
SELECT *, (SELECT COUNT(*) FROM `TABLE 1` WHERE userId = t.userId )
rank FROM `TABLE 1` t GROUP BY t.userId ORDER BY rank DESC
but in mongoDB i have no idea how to do

No comments:

Post a Comment