title: compare two arrays in mongodb?
body: <p>I have following collection</p>
  
  <pre><code>[
    {
      "receiverWorkout": {
        "_id": "5b4f3920c805e1299b90716c",
        "name": "nmbnmbnmnbm",
        "exercises": [
          {
            "_id": "5b4f3920c805e1299b90716f",
            "reps": 0,
            "weights": 0
          },
          {
            "_id": "5b4c3920c805e1299b90716f",
            "reps": 4,
            "weights": 0
          }
        ]
      },
      "senderWorkout": {
        "_id": "5b4f11f16cf99524f21d2287",
        "name": "nmbnmbnmnbm",
        "exercises": [
          {
            "_id": "5b4f11f16cf99524f21d2288",
            "reps": 12,
            "weights": 0
          },
          {
            "_id": "5b4f7920c805e1299b90716f",
            "reps": 8,
            "weights": 0
          }
        ]
      }
    }
  ]
  </code></pre>
  
  <p>I need to compare both the exercises array and add new field called <code>won</code> to only <code>senderWorkout</code> ... Winning will be calculated on the <code>reps</code> field... And same index exercises will be matched i.e. first with first exercise and second with second exercise...</p>
  
  <p>So my expected output will be</p>
  
  <pre><code>[
    {
      "receiverWorkout": {
        "_id": "5b4f3920c805e1299b90716c",
        "name": "nmbnmbnmnbm",
        "exercises": [
          {
            "_id": "5b4f3920c805e1299b90716f",
            "reps": 0,
            "weights": 0
          },
          {
            "_id": "5b4c3920c805e1299b90716f",
            "reps": 4,
            "weights": 0
          }
        ]
      },
      "senderWorkout": {
        "_id": "5b4f11f16cf99524f21d2287",
        "name": "nmbnmbnmnbm",
        "exercises": [
          {
            "_id": "5b4f11f16cf99524f21d2288",
            "reps": 12,
            "weights": 0,
            "result": "won"
          },
          {
            "_id": "5b4f7920c805e1299b90716f",
            "reps": 2,
            "weights": 0,
            "result": "lost"
          }
        ]
      }
    }
  ]
  </code></pre>