cts query to find unique values from a field from json document in Marklogic staging

4

I’m trying to write a javaScript cts query to query only unique values from a key from a json document based on another key. i.e, similar to a query like select distinct(name) from data-hub-staging where source=’source1′

{
    "source": "source1",
    "name": "John",
    "DOB": "1-01-1990",
    "load_date": "2021-10-23 10:23:55"
}

I have been trying the below query but it returns all the fields, I wanted only the name field.

const query = cts.jsonPropertyValueQuery(
              "source",
              "source1");

[...new Set (cts.search(query)
.toArray()
  .map(doc => doc.root.name).sort())]