Skip to content
Discussion options

You must be logged in to vote

@letuananh1873

Hi.

You can’t filter by manga.slug directly until after the $lookup, because slug lives in the joined documents (story). Also, your $lookup likely should join chapters.manga to manga._id (not id), unless you truly have an id field in manga.

Here is a correct approach.

$collection = self::raw(function ($collection) use ($manga_slug, $chapter_slug) {
    return $collection->aggregate([
        ['$match' => ['name' => $chapter_slug]],

        ['$lookup' => [
            'from' => 'manga',
            'localField' => 'manga',
            'foreignField' => '_id',
            'as' => 'story',
        ]],

        ['$unwind' => '$story'],

        ['$match' => ['story.slug' => $m…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by GromNaN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants