Collate MongoDb

2

I need to do an auto complete that consumes a mongodb database. The words can be written with or without accent, uppercase or lowercase, that is, I need to define a collage in the mongo that allows me to do a search that ignores accent and case sensitive.

Does mongo have this configuration module? If not, is there any way to resolve this with the C # driver?

var filterBuilder = Builders<UnidadeCurricular>.Filter;
var filter = filterBuilder.Exists(a => a.DeletedAt, false) & filterBuilder.Where(a => a.Nome.StartsWith(nome));
    
asked by anonymous 05.11.2015 / 13:47

2 answers

0

You have a query operator named $text .

An example of how to do this would be:

var comandoPesquisa = new CommandDocument
{
    { "text", typeof(UnidadeCurricular).Name },
    { "search", nome }
};

var commandResult = _database.RunCommandAs<TextSearchCommandResult<T>>(comandoPesquisa);

I pulled it out .

    
05.11.2015 / 15:28
0

In order to find both accented and non-accented words in the search, it is necessary to define a text index with the fields used in the search belonging to the collection. So:

db.collection.createIndex( { SEUCAMPOSTRING: "text" } )

and then to search define the language for Portuguese in the search.

db.collection..find({$text:{$search:"TEXTOPROCURADO",$language:'pt'}})

sources:

link link

    
03.12.2016 / 13:36