title: Database design that requires two searches
body: <p>I have played around with mongodb in the past, but this is the first time I am working on a project. </p>
  
  <p>I am designing a Spanish dictionary. However I am having trouble with the design. This is the first design. These are the objects that get stored in mongodb.</p>
  
  <p><strong>Dictionary collection</strong></p>
  
  <pre><code>{
      word:"comer",
      type:"infinitive",
     Definition:"A definiition for the word hablar",
      conjugation: {
          present: ["como", "comes", "come", "comemos", "coméis", "comen"],
          preterite:["comí", "comiste", "comió", "comimos", "comisteis", "comieron"],
      }
  },
  // Lets pretend that this is another verb with different conjugation forms.
  {
      word:"hablar",
      type:"infinitive",
     Definition:"A definiition for the word hablar",
      conjugation: {
          present: ["como", "comes", "come", "comemos", "coméis", "comen"],
          preterite:["comí", "comiste", "comió", "comimos", "comisteis", "comieron"],
      }
  }
  </code></pre>
  
  <p>With this design I can search for a word by comparing the <strong>word:"a word"</strong> property. The problem is that with this design searching for "como" isn't posible or at least not efficient.</p>
  
  <p>The second design has two collections <strong>Words</strong> and <strong>verbs</strong></p>
  
  <p><strong>Words</strong></p>
  
  <pre><code>{
      word:"como",
      infinitive:"comer",
  },
  {
      word:"comer",
      infinitive:"comer",
  },
  {
      word:"comemos",
      infinitive:"comer",
  },
  {
      word:"habla",
      infinitive:"hablar",
  }
  </code></pre>
  
  <p><strong>Verbs</strong></p>
  
  <pre><code>{
      word:"comer",
      Definition:"A definiition for the word comer",
      conjugation: {
          present: ["como", "comes", "come", "comemos", "coméis", "comen"],
          preterite:["comí", "comiste", "comió", "comimos", "comisteis", "comieron"],
      }
  },
  {
      word:"hablar",
      Definition:"A definiition for the word hablar",
      conjugation: {
          present: ["como", "comes", "come", "comemos", "coméis", "comen"],
          preterite:["comí", "comiste", "comió", "comimos", "comisteis", "comieron"],
      }
  }
  </code></pre>
  
  <p>With this design any word can be easily searched. Then the <strong>infinitive</strong> property can be used to search the <strong>Verbs</strong> collection.</p>
  
  <p>The problem now is that two searches are required to find a word. What is worse is that to find an infinitive like the word <strong>comer</strong> you first search the <strong>words</strong> Collection to find the same word <strong>comer</strong> before looking it up in the <strong>Verbs</strong> collection.</p>
  
  <p><strong>The questions</strong></p>
  
  <p>Is it unusual to have to perform two searches to find a word?</p>
  
  <p>Is this a bad design or can it be improved? </p>
  
  <p>Can I design this such that only one search is required.</p>
  
  <p><strong>Note:</strong> </p>
  
  <p>I understand that data can be stored in multiple collections and as such multiple searches may be required. But this is different since one search must be done before searching multiple collections to get the information we require. </p>