Mongodb Turkish character set problem

I am insert data

(name:'İstanbul') <-- problem big İ
filter: { 'Adi' :/is/i} { locale: 'tr', strength: 1 }

result: not found…
how can I solve the problem?

Hi :wave: @suleyman_yalcin,

Welcome to the MongoDB Community forums :sparkles:

If you refer to the MongoDB documentation for $regex here

It states:

Case-insensitive regular expression queries generally cannot use indexes effectively. The $regex implementation is not collation-aware and is unable to utilize case-insensitive indexes.

So, in this case, I’ll suggest you use MongoDB Atlas Search.

For example, consider the following sample data collection called names:

_id: ObjectId('6350d8ccb0ec2b79cdd7576c')
name: "İstanbul"

You can create an Atlas search index from the MongoDB Atlas dashboard:

The index will look something like this in JSON format:

{
  "analyzer": "lucene.turkish",
  "mappings": {
    "dynamic": true,
    "fields": {
      "name": [
        {
          "dynamic": true,
          "type": "document"
        },
        {
          "type": "autocomplete"
        }
      ]
    }
  }
}

After that, you can run the query using $search:

db.names.aggregate([
     {
    $search: {
        index: 'name_index',
        autocomplete: {
            query: 'is',
            path: 'name'
        }
    }
}
 ])

It will return the output as follows:

Output:
[ { _id: ObjectId("6350d8ccb0ec2b79cdd7576c"), name: 'İstanbul' } ]

For more info refer to the Atlas search documentation here

I hope it helps!

Thanks,
Kushagra

2 Likes