I have a project in mind to create a spell-check dictionary for text verification. The dictionary contains 20,000 words. With my Meteor application, the goal is to input the text, split it into words, and verify each word against the dictionary.
However, I am questioning if this is the most efficient approach. Processing a text with 100 words would result in 100 database calls, which does not feel optimal. On the other hand, loading 20,000 words into an array for lookup seems excessive.
let incorrect = [];
text.split(' ').forEach(word => {
if (!Dictionary.findOne({ word: word })) {
incorrect.push(word);
}
})
if (incorrect.length)
console.log('There is a spelling mistake');
else
console.log('Everything seems to be correct');
One alternative I'm considering is sending the array of split words as a query and receiving the missing elements as a result (array). However, I'm unsure if this can be achieved with MongoDB.