Order Software, Group B Mongo DB Laravel

I am new to Mongo DB and I am using jenssegers Library in my Laravel project. I have a table called "table1" that has columns "_id", "c1", "c2", "c3", "created_at". I need to convert the following SQL query to mongo db.

select *, count(c3) as total from
(select * from table1 
where c1 in ('1', '32', '6', ...) 
order by created_at desc) as temp 
group by c2 order by created_at desc

      

I need to select the entire column including "_id". I only need rows containing the maximum created_at value, 'order by' when grouped by column c2 and ordering the rows of the result using that created_at column.

I found this answer, but my question is a little more complicated. I think: StackOverflow question.

And it might be helpful and related to my problem: http://blog.chomperstomp.com/how-to-order-by-before-group-by-with-mysql/

+3


source to share


1 answer


You have to use the aggregation function in more detail mongodb.aggregation



0


source







All Articles