The object in MongoDB database looks like this which includes city names that have spaces in between -
{
"_id": ObjectId("65ofb9104b1cf1519e4c5957"),
"country": "us",
"city": "New York"
}
I would like to make a case insensitive search on the city names eliminating their white spaces.
Ex: matching for newyork should return all the documents with New York as a city name. So far, I have tried the following query which does the case insensitive search but it does not eliminate space in between.
db.getCollection('cities').aggregate([
{ $match: { "city": { '$regex': 'newyork' , $options: 'i' } } } ,
]);