For the life of me, I can't figure out how to write this query in MongoDB!
I need to return rows from a query where the max "Revision" is the row returned for an item
I have two parts:
- Return a count without actually getting the data.
- Return all the data (not necessarily in order by column A but would be helpful) based on the grouping.
Here's a sample set (In our real world data, we have ~40 columns and potentially millions of rows):
A B C D Revision
--------+-------+-------+-------+------------
Item1 100 200 300 1
Item1 111 222 333 2
Item2 200 500 800 1
Item2 222 555 888 2
Item2 223 556 889 3
Item3 300 600 900 1
Item4 400 700 1000 1
What I need to be returned:
- The returned count: 4
- The returned data:
A B C D Revision --------+-------+-------+-------+-------- Item1 111 222 333 2 Item2 223 556 889 3 Item3 300 600 900 1 Item4 400 700 1000 1
I've been trying so many combination or $group and $count and even tried to use
SQL to MongoDB query translation tools but can't seem to make it work.
Please help and thanks in advance!!