Database
db={"PastListenerLocation":[{"UUID":"c19c7dd1c7a4f2ca","timestamp":ISODate("2023-02-01T22:15:02.000+00:00"),"location":{"coordinates":[0.000,0.953512],"type":"Point"}}],"NowPlaying":[{"artist":"Carrie Underwood","song":"Garden","type":"S","timeplay":ISODate("2023-02-01T22:15:32.000+00:00"),"history":["c19c7dd1c7a4f2ca"]}]}
Query
db.PastListenerLocation.aggregate([{/*** query: The query in MQL.*/$match:{UUID:"c19c7dd1c7a4f2ca",timestamp:{$gte:ISODate("2023-02-01T22:15:02.000+00:00")}}},{$lookup:{from:"NowPlaying",let:{uuid:"$UUID",timestamp:{$toDate:{$multiply:[{$toLong:"$timestamp"},1]}}},pipeline:[{$match:{$expr:{$and:[{$in:["$$uuid","$history"]},{$and:[{$gte:[{$toLong:"$timeplay"},{$subtract:[{$toLong:"$$timestamp"},180000]}]},{$lte:[{$toLong:"$timeplay"},{$add:[{$toLong:"$$timestamp"},180000]}]}]}]}}},{$project:{_id:1,song:1,artist:1,type:1}}],as:"NowPlayingInfo"}}])