0

I want to get the number of items that meet the true condition in the status field for every cases. for example: Document

Output:

{“user_id”: “4-389-739”,“case1”:0,“case2”:3,“case3”:1,“case4”:1 } 
1
  • Please don't use images for code/data/errors/etc. Just include them in a code block. Commented Apr 10, 2022 at 12:27

1 Answer 1

1

The user id part is not sure from where you are getting in document i believe you can figure it out but for help you out with counting the cases this might help you

      {
    $group: {
     
      "case1": {
        $sum: {
          $cond: [{ $in: [true, "$case1.status"] }, 1, 0]
        }
      },
"case2": {
        $sum: {
          $cond: [{ $in: [true, "$case2.status"] }, 1, 0]
        }
      }
    }
  }

you can generalize here and add as many conditioin as possible
Sign up to request clarification or add additional context in comments.

1 Comment

user_id is included. you can find it at the end of the Document

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.