Using sorting in mounodb $ regex

Since v3.4 mappings are available for search operations, especially as matches for diacritical characters. While a search query with a specific value ($ eq opeartor or corresponding construct) will match letters and correspondent diacritics, the same is not the case if $ regex is used to achieve matching on a partial search string (a LIKE ').

Is there a way for a $ regex query to use matching just like a $ eq query?

consider an example testcoll collection:

{ "_id" : ObjectId("586b7a0163aff45945462bea"), "city" : "Antwerpen" }, 
{ "_id" : ObjectId("586b7a0663aff45945462beb"), "city" : "Antwërpen" }

this query will find both records

db.testcoll.find({city: 'antwerpen'}).collation({"locale" : "en_US", "strength" : 1});

the same query using a regular expression will not (finds a record only with "Antwerp")

db.testcoll.find({city: /antwe/i}).collation({"locale" : "en_US", "strength" : 1});
+4
1

?

var filter = Builders<BsonDocument>.Filter.Regex(query.Filtros[index].Clave, new BsonRegularExpression(string.Format(".*{0}.*", query.Filtros[index].Valor.ToString()), "i"));

                    for (index = 1; index < query.Filtros.Count(); index++)
                        filter = filter & (Builders<BsonDocument>.Filter.Regex(query.Filtros[index].Clave, new BsonRegularExpression(string.Format(".*{0}.*", query.Filtros[index].Valor.ToString()), "i")));
                        //filter = filter & (Builders<BsonDocument>.Filter.Eq(query.Filtros[index].Clave, query.Filtros[index].Valor.ToString()));
                        var result = collection.Find(filter).ToList();
                    output = JsonConvert.SerializeObject(result);
Hide result
0

Source: https://habr.com/ru/post/1665602/


All Articles