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

115
Views
I want to filter data in one array on one specific field with different condition in nodejs with mongodb But I Get the Result only last Condition

the below code gives the list of attendance whose WorkStatus is "P", it takes last $and value($and: {$eq: ["$$attendance.WorkStatus", "P"],},) from $filter, but i want to get count of each WorkStatus separately(i.e. "MIS","A","P").

{$facet: {totalCount: [{ $count: "sum" }],aggregatedData: [{$project: {date: "$date", attendance: { $filter: { input: "$attendance",as: "attendance",cond: {$and: { $eq ["$$attendance.WorkStatus", "MIS"], }, $and: {$eq: ["$$attendance.WorkStatus", "A"],},$and: { $eq: ["$$item.WorkStatus", "P"]

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

0

If you can get data using multiple conditions so you can use $or to match multiple conditions in query.

cond:$or: [{$and: { $eq ["$$attendance.WorkStatus", "MIS"], }, $and: {$eq: ["$$attendance.WorkStatus", "A"],},$and: { $eq: ["$$item.WorkStatus", "P"]}]

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!