Hi @Javier_Blanco ,
Usually if a query does not end it means that it is probably ineffecient…
With expressive lookups like this using indexes can be challenging it was mainly improved in 5.0+.
Now what you should verify is weather you have indexes on { idSensor : 1, idDevice}
on sensors collection. The device collection should have { _id : 1, “group.$id” : 1} indexed.
But again if you use server 5.0+.
Also try to limit the results to a small amount before running the unwind to check how fast do first results retrieved
Thanks
Pavel