I am using Mongoose in a MEAN environment. How can I make sure to not have any duplicate results in my result set? Example: my database contains 10 (partly duplicate) names:
- Allan
- Allan Fourier
- Allan
- Allan Maxwell
- Allan
- Allan Foo
- Allan Whatever
- Allan Whoever
- Allan Smith
- Allan Rogers
When querying this database for 'Allan' or maybe even just 'all' (using .find(regex...) and limiting the number of returned results to 5, I get this:
- Allan
- Allan Fourier
- Allan
- Allan Maxwell
- Allan
Having three duplicate entries of 'Allan', we waste a lot of result-diversity (talking about an autocomplete function for a search input field). I need the returned result set free of duplicates, such as:
- Allan
- Allan Fourier
- Allan Maxwell
- Allan Foo
- Allan Whatever
How can that be achieved using mongoose, if at all?