[Question] How to where other field of collection #1989
Unanswered
letuananh1873
asked this question in
General
Replies: 1 comment
-
|
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' => $manga_slug]],
]);
});Hope this helps. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a collection is manga (_id, title, slug) and chapter
At Chapter Model
Result show OK, but I want to where field slug of manga collection. How to do it?
Thank you so much!
Beta Was this translation helpful? Give feedback.
All reactions