Ticket : user report - "operation exceeded time limit" error

Hi everyone,

I have an issue with the ticket ‘user report’. To get the desired result I’m trying to perform a pipeline with a lookup foolowed by a sort. But the sort has an issue, I don’t understand why. I get an error : ‘Error in $cursor stage :: caused by :: operation exceeded time limit’ . The error is throwed both in Compass and when I performed the query in PyCharm. Here is the pipeline :

[
    {
        '$lookup': {
            'from': 'comments', 
            'let': {
                'email': '$email'
            }, 
            'pipeline': [
                {
                    '$match': {
                        '$expr': {
                            '$eq': [
                                '$email', '$$email'
                            ]
                        }
                    }
                }, {
                    '$count': 'count'
                }
            ], 
            'as': 'comments'
        }
    }, {
        '$sort': {
            'comments.count': 1
        }
    }
]

My cluster is on a mongoDBAtlas.
And the strangest thing is taht if I try to sort on any other attribute (’_id’, ‘name’…), I have the same issue.
Any clue on where the error could come from ?

Hi @Antoine_Chelveder_64847,

You need to understand the question more. We need lookup when two collections are involved. Try to work around which collection we need to work on.

Kanika

Hi @kanikasingla. Thanks for the answer. Indeed, I was going in a complicated way…
I find a way simpler way with a $group in ‘comments’ collections.
Although, I’m still wondering the issue I had on my first try. Even if it’s not the good way to perform the query, it looks like something that could work.