title: How can I Push only unique values into a array in mongoDB
body: <p>I have a like table. and in that like table I have a array called videoLikes. I need to store the userData who had liked the video. so when I am trying to push an object with userId field into that array I got duplicate datas. my userId is unique on model so I need to push only a user once in that array. I have tried $addToSet operation but it's not working properly.</p>
  <p><strong>My usecase is when a user tried to like the video second time it won't push to that array.</strong></p>
  <pre><code>{
    &quot;videoId&quot;: 275,
    &quot;likesCount&quot;: 4,
    &quot;videoLikes&quot;: [
      {
        &quot;userId&quot;: 149,
        &quot;uid&quot;: &quot;5B8slS9AqpeNMJWK5CgbwzdXhQ82&quot;,
        &quot;_id&quot;: {
          &quot;$oid&quot;: &quot;625569ecd56d19a1954f5cc2&quot;
        }
      },
      {
        &quot;userId&quot;: 149,
        &quot;uid&quot;: &quot;5B8slS9AqpeNMJWK5CgbwzdXhQ82&quot;,
        &quot;_id&quot;: {
          &quot;$oid&quot;: &quot;625569ecd56d19a1954f5cc4&quot;
        }
      },
      {
        &quot;userId&quot;: 149,
        &quot;uid&quot;: &quot;5B8slS9AqpeNMJWK5CgbwzdXhQ82&quot;,
        &quot;_id&quot;: {
          &quot;$oid&quot;: &quot;625569ecd56d19a1954f5cc0&quot;
        }
      },
      {
        &quot;userId&quot;: 149,
        &quot;uid&quot;: &quot;5B8slS9AqpeNMJWK5CgbwzdXhQ82&quot;,
        &quot;_id&quot;: {
          &quot;$oid&quot;: &quot;625569ecd56d19a1954f5cbe&quot;
        }
      }
    ]
  }
  </code></pre>