title: mongodb coalesce equivalent (with mongoose)
body: <p>I have a <strong>localization</strong> collection where each document is a key-value pair translated into multiple languages. </p>
  
  <p>This is a JSON representation:</p>
  
  <pre><code>[
    { "_id": "form.password" , "en": "Password"  , "he": "סיסמא"  , "ru": "пароль" }
    { "_id": "form.email"    , "en": "Email"     , "he": "אימייל" },
    { "_id": "form.firstname", "en": "First Name", "he": "שם פרטי", "ru": "Имя" }
  ]
  </code></pre>
  
  <p>This is a mongoose schema:</p>
  
  <pre class="lang-js prettyprint-override"><code>new Schema({
    _id: {
      type: String,
      required: true
    },
    en: String,
    he: String,
    ru: String
  });
  </code></pre>
  
  <p>I need to get all key-values per each language with express.js:</p>
  
  <pre class="lang-js prettyprint-override"><code>app.get('/api/locals', function(req, res) {
    Local.find().select( req.query.language ).exec(function(err, data) {
      res.json(data);
    });
  });
  </code></pre>
  
  <p>This works fine <strong>if each language has the values for all keys</strong> but I want to make a <strong>fallback</strong> where if some language has no value for a certain key then the english value will be used.</p>
  
  <p>I thought maybe I should use aggregation or mapReduce but I don't know how to implement this with mongoose.</p>
  
  <p>With SQL I used to write this query:</p>
  
  <pre class="lang-sql prettyprint-override"><code>SELECT key, COALESCE($language , en) as value FROM locals
  </code></pre>
  
  <p>Thanks in advance.</p>