Good evening,
I’m searching to translate this mysql query in mongodb, how is it ??
select d.surname, d.forename, c.name, rcs.year, rcs.name, r.raceId, r.fastestLapSpeed
from ((results r join drivers d on r.driverId = d.driverId)
join constructors c on c.constructorId = r.constructorId)
join races rcs on r.raceId = rcs.raceId
where r.fastestLapSpeed > (
select avg(rr.fastestLapSpeed)
from results rr
where rr.raceId = r.raceId
group by rr.raceId
)
To experiment and help you we in the absence of sample documents, we would need to manually create document that matches the field names you are using. That’s very tedious.
In your original SQL, there were mentions of table drivers, constructors and races but in the Mongo version, it looks like you only have 2 collections. The mapping for drivers is quite obvious, but how is resultsConstructorsStatus related to constructors and races. Sample documents could help understanding that too.