How to create a perferct index based on a query

Hi Team,

I am having a collection and a query is executing as follows and based on the query i had created an index and the the query is taking the correct index but from application it is much slow to display the results, Please help to create a perfect index to display results faster, Kindly help me in this matter.

[{"$match":{"$or":[{“sId”:“D”,“dId”:“869247047809394”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“B”,“dId”:“869247047809394”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“B”,“dId”:“356849088459441”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“D”,“dId”:“356849088459441”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“D”,“dId”:“862818045326057”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“B”,“dId”:“862818045326057”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“B”,“dId”:“862818045336478”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“D”,“dId”:“862818045336478”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“D”,“dId”:“862818045447093”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“B”,“dId”:“862818045447093”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“B”,“dId”:“865006041831992”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“D”,“dId”:“865006041831992”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“D”,“dId”:“869247047838740”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“B”,“dId”:“869247047838740”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“B”,“dId”:“862818041586670”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“D”,“dId”:“862818041586670”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“D”,“dId”:“869247047837429”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“B”,“dId”:“869247047837429”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“B”,“dId”:“862818045408509”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“D”,“dId”:“862818045408509”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“B”,“dId”:“869247047734188”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“D”,“dId”:“869247047734188”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“B”,“dId”:“862818045348358”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“D”,“dId”:“862818045348358”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“B”,“dId”:“869247047720997”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“D”,“dId”:“869247047720997”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“B”,“dId”:“869247047756165”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“D”,“dId”:“869247047756165”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“B”,“dId”:“869247047832438”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“D”,“dId”:“869247047832438”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“D”,“dId”:“869247048595570”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“B”,“dId”:“869247048595570”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“D”,“dId”:“862818045336312”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“B”,“dId”:“862818045336312”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“B”,“dId”:“869247048697434”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“D”,“dId”:“869247048697434”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“D”,“dId”:“869247048554528”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“B”,“dId”:“869247048554528”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“D”,“dId”:“862818045409598”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“B”,“dId”:“862818045409598”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“B”,“dId”:“356849088479381”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“D”,“dId”:“356849088479381”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“D”,“dId”:“865006041911687”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“B”,“dId”:“865006041911687”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“D”,“dId”:“862818045441880”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“B”,“dId”:“862818045441880”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“B”,“dId”:“356158069620207”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“D”,“dId”:“356158069620207”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“B”,“dId”:“865006041907974”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“D”,“dId”:“865006041907974”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“B”,“dId”:“35615869590361”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“D”,“dId”:“35615869590361”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“B”,“dId”:“865006041779514”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“D”,“dId”:“865006041779514”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“D”,“dId”:“865006041855165”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“B”,“dId”:“865006041855165”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“B”,“dId”:“869247047800187”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“D”,“dId”:“869247047800187”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“B”,“dId”:“862818045421122”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“D”,“dId”:“862818045421122”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“B”,“dId”:“869738067222435”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“D”,“dId”:“869738067222435”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“B”,“dId”:“869738067380522”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“D”,“dId”:“869738067380522”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“B”,“dId”:“355026070124025”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“D”,“dId”:“355026070124025”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":-30.0}},{“tmp”:{"$lt":50.0}}]},{“sId”:“B”,“dId”:“869247047788119”,“temperatureLogTime”:{"$gt":{"$date":“2022-12-01T08:46:59.874Z”}},"$or":[{“tmp”:{"$gt":2.0}},{“tmp”:{"$lt":8.0}}]},{“sId”:“D”}]}}]},“planSummary”:"IXSCAN { sId: -1, dId: -1, temperatureLogTime: -1, tmp: -1 }, IXSCAN { sId: -1, dId: -1, temperatureLogTime: -1, tmp: -1 }, IXSCAN { sId: -1, dId: -1, temperatureLogTime: -1, tmp: -1 }, IXSCAN { sId: -1, dId: -1, temperatureLogTime: -1, tmp: -1 }, IXSCAN { sId: -1, dId: -1, temperatureLogTime: -1, tmp: -1 }, IXSCAN { sId: -1, dId: -1, temperatureLogTime: -1, tmp: -1 }, IXSCAN { sId: -1, dId: -1, temperatureLogTime: -1, tmp: -1 }, IXSCAN { sId: -1, dId: -1, temperatureLogTime: -1, tmp: -1 }, IXSCAN { sId: -1, dId: -1, temperatureLogTime: -1, tmp: -1 }, IXSCAN { sId: -1, dId: -1, temperatureLogTime: -1, tmp: -1 }, IXSCAN { sId: -1, dId: -1, temperatureLogTime: -1, tmp: -1 }, IXSCAN { sId: -1, dId: -1, temperatureLogTime: -1, tmp: -1 }

Thanks&Regards,
M. Ramesh.

Hi @MERUGUPALA_RAMES,

I cleaned up your query so we could read it… Next time it would be nice to do it yourself before you post it.

[{
    "$match": {
        "$or": [{
            "sId": "D",
            "dId": "869247047809394",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "B",
            "dId": "869247047809394",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "B",
            "dId": "356849088459441",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "D",
            "dId": "356849088459441",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "D",
            "dId": "862818045326057",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "B",
            "dId": "862818045326057",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "B",
            "dId": "862818045336478",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "D",
            "dId": "862818045336478",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "D",
            "dId": "862818045447093",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "B",
            "dId": "862818045447093",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "B",
            "dId": "865006041831992",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "D",
            "dId": "865006041831992",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "D",
            "dId": "869247047838740",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "B",
            "dId": "869247047838740",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "B",
            "dId": "862818041586670",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "D",
            "dId": "862818041586670",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "D",
            "dId": "869247047837429",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "B",
            "dId": "869247047837429",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "B",
            "dId": "862818045408509",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "D",
            "dId": "862818045408509",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "B",
            "dId": "869247047734188",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "D",
            "dId": "869247047734188",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "B",
            "dId": "862818045348358",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "D",
            "dId": "862818045348358",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "B",
            "dId": "869247047720997",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "D",
            "dId": "869247047720997",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "B",
            "dId": "869247047756165",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "D",
            "dId": "869247047756165",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "B",
            "dId": "869247047832438",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "D",
            "dId": "869247047832438",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "D",
            "dId": "869247048595570",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "B",
            "dId": "869247048595570",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "D",
            "dId": "862818045336312",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "B",
            "dId": "862818045336312",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "B",
            "dId": "869247048697434",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "D",
            "dId": "869247048697434",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "D",
            "dId": "869247048554528",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "B",
            "dId": "869247048554528",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "D",
            "dId": "862818045409598",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "B",
            "dId": "862818045409598",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "B",
            "dId": "356849088479381",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "D",
            "dId": "356849088479381",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "D",
            "dId": "865006041911687",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "B",
            "dId": "865006041911687",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "D",
            "dId": "862818045441880",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "B",
            "dId": "862818045441880",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "B",
            "dId": "356158069620207",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "D",
            "dId": "356158069620207",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "B",
            "dId": "865006041907974",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "D",
            "dId": "865006041907974",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "B",
            "dId": "35615869590361",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "D",
            "dId": "35615869590361",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "B",
            "dId": "865006041779514",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "D",
            "dId": "865006041779514",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "D",
            "dId": "865006041855165",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "B",
            "dId": "865006041855165",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "B",
            "dId": "869247047800187",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "D",
            "dId": "869247047800187",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "B",
            "dId": "862818045421122",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "D",
            "dId": "862818045421122",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "B",
            "dId": "869738067222435",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "D",
            "dId": "869738067222435",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "B",
            "dId": "869738067380522",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "D",
            "dId": "869738067380522",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "B",
            "dId": "355026070124025",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {
            "sId": "D",
            "dId": "355026070124025",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": -30.0}}, {"tmp": {"$lt": 50.0}}]
        }, {
            "sId": "B",
            "dId": "869247047788119",
            "temperatureLogTime": {"$gt": {"$date": "2022-12-01T08:46:59.874Z"}},
            "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}]
        }, {"sId": "D"}]
    }
}]

Before we talk about indexes, I see several problems with this query.

  1. "$or": [{"tmp": {"$gt": 2.0}}, {"tmp": {"$lt": 8.0}}] this takes any tmp greater than 2.0 OR any tmp less than 8.0. So basically it takes ALL tmp… It doesn’t filter anything. If you want the tmp between 2.0 and 8.0, it should be {tmp: {"$gt": 2.0, "$lt": 8.0}}. If “tmp” is an array, you probably want $elemMatch as well.
  2. Last condition in your massive $or is just {"sId": "D"}. Just because of this, you can remove like 50% of the query as this allows all the docs with {"sId": "D"} in the result set.

If you explain what you are trying to do with this query and provide a few document samples and the expected output, maybe I could come up with a better way to achieve this query.

Indexes: { sId: 1, dId: 1, temperatureLogTime: 1, tmp: 1 } isn’t bad but it might not be the best depending on the cardinality and data distribution of temperatureLogTime and tmp. We could also invert these 2 to gain some performances.
Same for sId and dId. I would put the one with the greater cardinality first to eliminate docs faster and reduce the number of index entries that need to be accessed. From what I’m seeing maybe dId has a better cardinality.

I hope this helps a bit.
Cheers,
Maxime.