How does mongo implement mysql-like nested queries?

  mongodb, question

At present, we are doing a mongodb data analysis project statistical analysis function
Description:
(1) The basic statistical data are counted irregularly;
(2) the query and display cycle is fixed to (hours, days, months, years), etc.;
(3) The corresponding data shall be counted as sum and avg according to the corresponding fields and the fields corresponding to group by.
(4) Paging function is also required;

The previous implementation in mysql was the following sql statement:
-Create a table structure
— CREATE TABLE test(
— id int PRIMARY KEY auto_increment,
— name varchar(30),
— score int
— );

-Insert test data
— insert into test (name,score)VALUES(‘a’,1);
— insert into test (name,score)VALUES(‘b’,2);
— insert into test (name,score)VALUES(‘c’,3);
— insert into test (name,score)VALUES(‘a’,2);
— insert into test (name,score)VALUES(‘b’,3);
— insert into test (name,score)VALUES(‘c’,1);

The specific implementation of SQL statements:
SELECT * FROM (SELECT name ,sum(score) totle from test GROUP BY name) tem order by totle desc LIMIT 0,2 ;

May I ask which great god can help? Thank you!

db.test.aggregate({“$project”:{“name”:1, “score”:1, “totle”:1}}, {“$group”:{“_id”:”$name”, “count”:{“$sum”:”$score”}}},{“$sort”:{“totle”:1}},{“$limit”:2})
I don’t know if it is feasible.