Is it possible to runCommand distinct with substr on the key I'm targeting?
I keep getting missing : after property id :
db.runCommand(
{
distinct: "mycollection",
key: {"myfield" : { $substr: { "$myfield", 0, 10 } }},
}
)
Is it possible to runCommand distinct with substr on the key I'm targeting?
I keep getting missing : after property id :
db.runCommand(
{
distinct: "mycollection",
key: {"myfield" : { $substr: { "$myfield", 0, 10 } }},
}
)
Copyright © 2021 Jogjafile Inc.
Can't do this with
runCommanddistinct. You need to use the agg framework to process the field and then get distinct values using$group, thusly:Very often it is useful to get the count of those distinct values: