'case sensitive aggregation in mongodb using mongoose
Hi all I am trying to do a auto populate dropdown search using mongoose and mongodb. I have written a aggregate query which works case insensitive was like if there are 2 datas like "brand" and "Brand" if i give "brand" it gives output for both "brand" and "Brand". Below is my aggregate query
var aggregate = model.aggregate([
{
$match:{
deleted: false
}
},
{
$group: {
_id: $brand,
Id: { $first: '$_id' },
count: { $sum: 1 }
}
},
{
$project: {
_id: '$Id',
name: '$_id',
count: '$count',
insensitive: { $toLower: '$_id' }
}
},
{ $sort: { insensitive: 1 } },
{
$project: {
_id: '$_id',
name: '$name',
count: '$count'
}
},
] );
My use case here is that i should display only the data specified like if i give brand it should display only "brand" and not "Brand". Kindly help me
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
