Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

110
Views
How to match in double nested array fields using aggregate in mongodb?

Below is the code I am trying but unable to get the desired results. matching on jobid and email.

    mongoConn.aggregate({
                    collectionName: Collection.jobactivity,
                    data: [
                        { $unwind: '$jobs' },
                        { $match: { '$and': [{ 'jobs.jobid': candidateJobHistoryObj.jobid}, {'jobs.activity.email':  candidateJobHistoryObj.candidateemail  }] }},
                        { $project: ({ '_id': 0, 'jobs.activity.activityname': 1, 'jobs.activity.firstname': 1, 'jobs.activity.middlename': 1, 'jobs.activity.lastname': 1, 'jobs.activity.createddatetime': 1, 'jobs.activity.createdbyuserid': 1, 'jobs.activity.modifiedtime': 1, 'jobs.activity.modifiedbyuserid': 1 }) },
                        { $sort: { 'jobs.activity.createddatetime': -1 } }
                    ],
                })

Json code present in mongodb:

    {
        "_id" : ObjectId("61c9d42fc87b10aab2e6732a"),
        "accountid" : 122,
        "jobs" : [
            {
                "jobid" : 12,
                "activity" : [
                    {
                        "firstname" : "Vikas Yadav Bhai",
                        "middlename" : null,
                        "lastname" : "Yadav",
                        "email" : "candidate1@abc.com",
                        "activityname" : "inserted the data into candidate engagement workflow",
                        "modifiedbyuserid" : 151,
                        "modifiedtime" : ISODate("2015-12-01T05:30:00.000+05:30"),
                        "createdbyuserid" : 151,
                        "createddatetime" : ISODate("2015-08-12T00:00:00.000+05:30")
                    },
                    {
                        "firstname" : "Vikas Yadav Bhai",
                        "middlename" : null,
                        "lastname" : "Yadav",
                        "email" : "candidate2@abc.com",
                        "activityname" : "updated the job details",
                        "modifiedbyuserid" : 151,
                        "modifiedtime" : ISODate("2015-12-01T05:30:00.000+05:30"),
                        "createdbyuserid" : 151,
                        "createddatetime" : ISODate("2015-08-12T00:00:00.000+05:30")
                    }
    ]
    }
    ]
    }

I want to match the documents where email is => candidate1@abc.com and jobid = 12

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

db.collection.find({
  "jobs.activity.email": "candidate1@abc.com",
  "jobs.jobid": 12
})

Check out the official document on dot notation if you want more details.

Here is the Mongo playground for your reference.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!