0

I am running a query which is having more values in the $in as below. My collection is having 5 million documents.

Can anyone give suggestions on how to write an efficient query?

{
    "_id":{
        "$gt":objectId1,
        "$lt":objectId2
    },
    "isActive":{
        "$ne":false
    },
    "$or":[
        {
            "$and":[
                {
                    "_id":{
                        "$in":[
                            "largeArray"
                        ]
                    }
                },
                {
                    "_id":{
                        "$nin":[
                            "smallarray"
                        ]
                    }
                }
            }
        ],
        {
            "friendId":{
                "$in":[
                    "largeArray"
                ]
            },
            "type":{
                "$ne":"thread"
            }
        },
        {
            "friendId":{
                "$in":[
                    "largeArray"
                },
                "groupId":{
                    "$in":[
                        "mid array"
                    ]
                }
            },
            {
                "friendId":{
                    "$in":[
                        "largeArray"
                    ]
                },
                "sharedGroupId":{
                    "$in":[
                        "mid array"
                    ]
                }
            }
        ]
    }

I am trying to get last month's record(post) from the current date, which user you are a friend, which group you join and what post share by a friend of his friend.

0 Answers0