• Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

105
Views
Mongoose don't select the record that didn't joined with any, at $lookup

I am able to successfully implement the lookup, but the problem is that; I don't need the records which doesn't have any record to join in child collection. Currently I am getting blank array for child field, if no matching record found in child collection. Note: I am using MongoDB Flexible Schema

$lookup: {
    from: 'childCollection',
    let: {
        typeId: {
            '$toObjectId': '$typeId'
        }
    },
    pipeline: [{
        $match: {
            $expr: {
                $eq: ['$_id', '$$typeId']
            },
            $or: [{
                'field1': {
                    $regex: 'searchkey',
                    $options: "i"
                }
            }, {
                'field2': {
                    $regex: 'searchkey',
                    $options: "i"
                }
            }]
        }
    }],
    as: 'test'
}
9 months ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.