Suppose I have a MongoDB where I have separate texts which consist of statements.
I need to be able to search for the texts, which have certain keywords in statements (also multiple texts that have an occurrence of a search term).
I also need to be able to find all the statements in all the texts added by a particular user, which contain a particular search phrase.
My question: do I need to create a separate collection for statements or can I simply add them as nested into the texts collection?
So, option 1 (separate collections):
Texts collection
text: {
name: 'nabokov',
id: '1'
}
Statements collection:
statement: {
text_id: '1',
id: '24',
text: 'He opened the window and saw the sky`
}
Option 2 (nested):
text: {
name: 'nabokov',
id: '1'
statements: [
id: '24',
text: 'He opened the window and saw the sky`
]
}
Which MongoDB storage schema is better if I want to retrieve statements separately based on keyword search and retain the contextual data (e.g. which text they belong to etc.)
How would this affect the write / read speed for larger DBs (e.g. > 100 Gb).
My texts would be limited to 16 Mb.