Links for this example
About this example
This example is a variation of the original Search a Database example. Instead of getting dropdown options from a table or dedicated collection of options, the options are retrieved from a regular data collection using the distinct() function of the query which removes the duplicates from the results. The results are then converted to objects and assigned to the dropdown list.
When a query uses the distinct() function, only the unique values are retrieved. Like the query’s find() function, distinct() runs the query and returns a Promise of the result. However, unlike find() which returns collection items as objects, distinct() returns a result with the distinct (no duplicates) field values.
Note: when using distinct(), there is no need for find(). In fact, using find() with distinct() will cause an error.