I have got the next SQL (mysql) question, as well as I might similar to transform it to MongoDB. It's mainly getting the highest 1 doc inwards each grouping:
SELECT A.*
FROM adverts AS A
INNER JOIN (SELECT id
FROM adverts
WHERE userId = 1
GROUP BY ad_code
HAVING MAX(ad_timestamp)) AS B ON B.id = A.id
From what I have got learn to date at that place are a number of methods to combination information inwards MongoDB (more than information at MongoDB aggregation comparison: group(), $group and MapReduce):
- grouping (does non piece of work on sharded collections)
- MapReduce
- $grouping
I'm attempting to unravel this with the MongoDB aggregation framework. To date I have got this:
db.adverts.combination([
,
])
However this does non homecoming the _ids of the matching paperwork, simply the advertisement code as well as max timestamp, so I can't exercise the information to acquire entire paperwork.
This inquiry seems really related, however it doesn't appear to unravel the identical number I'm having: Query one document per association from MongoDB
Thanks
Posted inwards S.E.F
by way of StackOverflow & StackExchange Atomic Web Robots
This Inquiry have got been answered
HERE