title: Get unique array values records with one value exist
body: <p>I have messenging platform in my app and I'm saving each message in the following format</p>
  
  <pre><code>{
     userIds: [ 'user1Id', 'user2Id' ],
     msg: "message",
     sentBy: 'user1',
     sentAt: new Date()
  }
  
  
  {
     userIds: [ 'user1Id', 'user3Id' ],
     msg: "message",
     sentBy: 'user1',
     sentAt: new Date()
  }
  
  
  {
     userIds: [ 'user1Id', 'user2Id' ],
     msg: "message",
     sentBy: 'user1',
     sentAt: new Date()
  }
  </code></pre>
  
  <p>Is there any way to get unique  conversations from the collection?</p>
  
  <p>for example from above list I want to get</p>
  
  <pre><code>  {
         userIds: [ 'user1Id', 'user2Id' ],
         msg: "message",
         sentBy: 'user1',
         sentAt: new Date()
      }
  
  
      {
         userIds: [ 'user1Id', 'user3Id' ],
         msg: "message",
         sentBy: 'user1',
         sentAt: new Date()
      }
  </code></pre>
  
  <p>these two records,</p>
  
  <p>What can be the mongo query here?</p>
  
  <p>Is there any other way  than querying all the records and do unique manually?</p>
  
  <p>or anyone suggests better schema, I just started with this feature so I'm in a position to change schema.</p>
  
  <p>I consider using like </p>
  
  <pre><code>{
     userIds: [ 'user1Id', 'user2Id' ],
     msgs: [
      {
         msg: "message",
         sentBy: 'user1',
         sentAt: new Date()
      },
      {
         msg: "message",
         sentBy: 'user2',
         sentAt: new Date()
      }
    ],
     modifiedAt: new Date()
  }
  </code></pre>
  
  <p>but decided against it because whenever there is new msg added to msgs array the whole field will be sent to client so using the first schema.</p>
  
  <p>Any suggestions appreaciated. Thanks.</p>