Litedb: Are case insensitive queries possible?

Created on 12 Jul 2017  路  2Comments  路  Source: mbdavid/LiteDB

I tried doing something like this. Which works with Mongodbs driver but doesn't seem to work here.
It keeps throwing an exception but the exception is null.

List<ComposerMdb.MongoConnection> connRets = null;
using (var db = new LiteDatabase(conn.DatabaseFilePath))
{
    connRets = db.GetCollection<ComposerMdb.MongoConnection>().Find(c => c.Name.ToUpper() == name.ToUpper()).ToList();
}

Most helpful comment

Even more late, you can create expression index to search using only lower (or upper) case.

db.EnsureIndex("idx_name", "LOWER($.Name)");

db.Find(Query.EQ("idx_name", nameVar.ToLower()));

All 2 comments

It's a bit late but for anyone looking for a solution you can query over the tow possibilities with Query.Or
string lower = value?.ToLower();
string upper = value?.ToUpper();
return col.Find(Query.Or(Query.Contains(field, lower), Query.Contains(field,upper))).ToList();

Even more late, you can create expression index to search using only lower (or upper) case.

db.EnsureIndex("idx_name", "LOWER($.Name)");

db.Find(Query.EQ("idx_name", nameVar.ToLower()));

Was this page helpful?
0 / 5 - 0 ratings

Related issues

muhamad picture muhamad  路  3Comments

furesoft picture furesoft  路  4Comments

MoamenMohamed picture MoamenMohamed  路  4Comments

kuiperzone picture kuiperzone  路  4Comments

rstat1 picture rstat1  路  3Comments