c# – Collate MongoDb

Question:

I need to do an auto complete that consumes a database in mongodb. Words can be written with or without an accent, upper or lower case, that is, I need to define a collate in mongo that allows me to do a search that ignores the accent and the case sensitive.

Does mongo have this configuration module? If not, is there any way to solve 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));

Answer:

It has a query operator called $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 took it from here .

Scroll to Top