title: MongoDB Schema Design for language database
body: <p>I need some advice on MongoDB schema design for a natural language database. </p>
  
  <p>I need to store for each language texts and words like:</p>
  
  <pre><code>lang: {
      _id: "English",
      texts : [
          {   text : "This is a first text", 
              date : Date("2011-09-19T04:00:10.112Z"),
              tag : "test1"
          },
          {   text : "Second One", 
              date : Date("2011-09-19T04:00:10.112Z"),
              tag : "test2"
          }
      ],
      words : [
          {   
              word : "This",
          },
          {   
              word : "is",
          },
          {   
              word : "a",
          },
          {   
              word : "first",
          },
          {   
              word : "text",
          },
          {   
              word : "second",
          },
          {   
              word : "one",
          }
  
  
      ]
  
  }
  </code></pre>
  
  <p>And then I need to know each words and texts a user has associated. The word/text amount tends to be huge and I need to list all words on a language and all words a user has associated for that language.</p>
  
  <p>From my perspective I think storing the user_ids that are associated with a given word in an array for the word is maybe a good approach like:</p>
  
  <pre><code>lang: {
      _id: "English",
      texts : [
                  ...
      ],
      words : [
          {   
              word : "This",
              users: [user1,user2,user3]
          },
          {   
              word : "is",
                  users: [user1,user2]
                  },
                  ...
      ]
  }
  </code></pre>
  
  <p>Having in mind that a word can be associated to hundreds of thousand of users and the document limit (as I read) is 4MB and that I need to:</p>
  
  <ol>
  <li>List all words for a given user and language</li>
  </ol>
  
  <p>Is this a good approach? Or can you think of a better one?</p>
  
  <p>Hope this question is clear enough and that someone can give me a help on this ;)</p>
  
  <p>Thank you all!</p>