Is there a query in MongoDb that will allow me to search a key (not the value-- e.g. subject: English)? I want to load a dropdown menu with “subjects”. For example, let’s say there are 100 documents and 20 are math, 20 English, 20 Spanish, 20 science, and 20 history. In this example, there are 5 subjects( math, English, Spanish, science, and history) that should populate in the drop down menu. Is this possible with mql?
Hello @david_h, You can use the
db.collection.distinct("subject") method to get unique
subjectvalues. Note the method returns an array of the subjects, e.g.,
[ "English", "Math", ... ]. And, you can populate the drop down menu from the array data.