title: MongoDB Mongoose dynamic fields
body: <p>I'm developing a website in which each user has a number of balances for different currencies. Throughout the lifetime of the website I will regularly add new currencies. </p>
  
  <p>I'm trying to figure out the best way to store the balances using mongoose. I currently atore the balances like this: </p>
  
  <pre><code>var UserSchema = new Schema({
      ...
      balances: {
          mck: {
              type: Number,
              default: 100.0,
              addresses: String
          },
          btc:{
              type: Number,
              default: 10.0,
              address: String
          }
      }
  
  });
  </code></pre>
  
  <p>But it doesn't seem like the best approach. each time I want to add a new currency the existing documents will not contain it. <strong>Are there disadvantages to allowing documents in the database which are out of sync with the schema?</strong></p>
  
  <p>I thought of making the schema more dynamic by using a subdocument to store currencies and their respective balances like this:</p>
  
  <pre><code>var BalanceSchema = new Schema({
      currency: String,
      amount: Number,
      address: String
  });
  </code></pre>
  
  <p>But there would be a painful number of callbacks to deal with when changing balances etc. </p>
  
  <p><strong>Which of these methods would be the best approach? Or is there another I have missed?</strong></p>