I need a distinct const addresses = await strapi.entityService.findMany( 'api::[...].[...]', {

How can I do a distint on strapi, what i am targeting is (api::[…].[…]) which contains an array addresses, which is an array of objects containing city and province, I want to get an object with unique cities and provinces

This topic has been created from a Discord post (1238464154617122816) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord

const provincesWithCities = {};

items.forEach(partnership => {
item.addresses.forEach(address => {
const province = address.province;
const city = address.city;

// If province is not already in provincesWithCities, initialize it with an empty array
if (!provincesWithCities[province]) {
  provincesWithCities[province] = {
    province: province,
    cities: []

// Add city to the cities array for the province
if (!provincesWithCities[province].cities.includes(city)) {


// Convert provincesWithCities object into an array of province objects
const distinctProvinces = Object.values(provincesWithCities);

I need something like this

You can do that only using strapi.db.connection

await strapi.db.connection.select("*").from("demos")