How to keep duplicate values in variable?

I have a mongo db data souce which queries the name field from collection. I have duplicate name values but in variable dropdown i only see each name once. example. i have 2 names TEST, TEST in my db i only see single TEST in variable dropdown. I want all of them. All of name field have unique _id as well. not sure how to use that to get every name in variable ?below is my aggregation-[
{
“$group”: {
“_id”: null,
“names”: {
“$addToSet”: “$name”
}
}
},
{
“$unwind”: “$names”
},
{
“$project”: {
“_id”: 0,
“name”: “$names”
}
},
{
“$sort”: {
“name”: 1
}
}
]

What is the result of this query when it is run in mongodb, outside of grafana.

@yosiasz : this query did not give the duplicates outside grafana. I tried below simple query which gave me duplicates outside grafana but did not give duplicates names in grafana.[
{
“$project”: {
“_id”: 0,
“name”: 1
}
},
{
“$sort”: {
“name”: 1
}
}
]

1 Like

so it seems like there might be a bug there. so you will need to trick grafana to bypass this issue by doing something like the following in mongodb query

select unique_id as __value, name as __text
 from chocolate_croissants

let me test and if this is an issue with mssql

I learnt from web that i should be using push operator instead of addToSet in my query to keep the duplicates and that worked outside grafana. I could see duplicates but in grafana push did not give any duplicates.

i think you might have found a bug, submit it to gitlab

1 Like