title: Mongoose - Add 'is_self' field in aggregate
body: <p>I'm building a chat app, that should retrieve all new messages from MongoDB, grouped in to conversations. But each message should have a new 'is_self' field</p>
  
  <p>Edit:
  The 'is_self' field contains a boolean for if the message if from the user.</p>
  
  <p>so pseudo:</p>
  
  <pre><code>is_self: {$cond: {if: {message.sender == MYID)}, then: true, else: false}
  </code></pre>
  
  <p>So lets say I have Message model</p>
  
  <pre><code>    var MessageSchema  = new Schema({
      conversation_id:{type: mongoose.Schema.ObjectId, ref: 'Conversation', required: true},
      message: {type: String, required: true},
      sender: {type: mongoose.Schema.ObjectId, ref: 'User'},
      created: {type: Date, default: Date.now},
      read: {type: Boolean, default: false}
  });
  </code></pre>
  
  <p>And a Conversation model</p>
  
  <pre><code>    var ConversationSchema = new Schema({
      from: {type: mongoose.Schema.ObjectId, ref: 'User', required: true},
      to: {type: mongoose.Schema.ObjectId, ref: 'User', required: true},
      last_changed: {type: Date, default: Date.now},
      created: {type: Date, default: Date.now}
  });
  </code></pre>
  
  <p>Now I try to do an Aggregate, to load all messages that are inside a conversation_id array and are created > last_checked date... </p>
  
  <p>So it looks like this:</p>
  
  <pre><code>mongoose.model("Message").aggregate([
              // First find all messages
              {
                  $match: {
                      $and: [{conversation_id: {$in: idArray}}, {created: {$gt: lastChecked}}]
                  }
              },
              // Add is self field
              {
                  $group: {
                      _id: $_id,
                      $is_self: {
                          $cond: {'if(message.sender == MYID then true else false': '??'}
                      }
                  }
              },
              // Sort by date
              {$sort: {created: -1}},
  
              // Then group by conversation
              {
                  $group: {
                      _id: '$conversation_id',
                      messages: {
                          $push: '$$ROOT'
                      },
  
                  }
              }
              // TODO: find users for unknown conversation
              /*,
              {
                  $project: {
                      user: {
                          $or: [{conversation_id: {$in: knownConversations}}]
                      }
                  }
              }*/
          ])
  </code></pre>
  
  <p>I tried with $cond and if / else statement but Mongo doesn't allow that..</p>
  
  <p>Thanks!</p>