title: mongoose schema field associate array
body: <p>My schema looks like:</p>
  
  <p><code>var Article = new mongoose.Schema({
      sentenceArray: {}
  });
  </code></p>
  
  <p>The purpose of having <code>sentenceAudioArray: {}</code> is so that I can add <code>{sentId,sentText}</code> tuples to my article. This can be achieved through a standard Array ( <code>sentenceArray: []</code> ), but retrieval will not be O(1) (ie, id I know a sentId, I cannot simply call <code>sentenceArray[sentId]</code> to retrieve).</p>
  
  <p>In my createArticle methods, I have </p>
  
  <pre><code>newArticle.sentenceArray = {};
  </code></pre>
  
  <p>This doesnt seems to create the field in mongo. When I look at the database, this field sentenceArray is not created. Consequently, when I do </p>
  
  <pre><code>anArticle.sentenceArray[sentId] = "Some Sentence"
  </code></pre>
  
  <p>I get an error that sentenceArray is undefined.</p>
  
  <p>Any suggestions on how to use Associative Array within a Mongoose schema. </p>
  
  <p>Edit: Please note that the objective is to be able to add multiple sentences to sentenceArray. I expect to call</p>
  
  <pre><code>anArticle.sentenceArray["firstSent"] = "Some Sentence";
  
  anArticle.sentenceArray["secondSent"] = "Another Sentence";
  
  anArticle.sentenceArray["thirdSent"] = "Yet Another Sentence";
  </code></pre>
  
  <p>and later on, call</p>
  
  <pre><code>console.log(anArticle.sentenceArray["thirdSent"])
  </code></pre>