litedb-org/LiteDB · error · NotSupportedException
Operator not supported {nodeType}
Error message
Operator not supported {nodeType} What it means
Thrown by GetOperator when a BinaryExpression uses an ExpressionType not in the supported set. Supported operators: Add (+), Multiply (*), Subtract (-), Divide (/), Equal (=), NotEqual (!=), GreaterThan (>), GreaterThanOrEqual (>=), LessThan (<), LessThanOrEqual (<=), And/AndAlso (AND), Or/OrElse (OR). Any other binary operator triggers this error.
Source
Thrown at LiteDB/Client/Mapper/Linq/LinqExpressionVisitor.cs:623
switch (nodeType)
{
case ExpressionType.Add: return " + ";
case ExpressionType.Multiply: return " * ";
case ExpressionType.Subtract: return " - ";
case ExpressionType.Divide: return " / ";
case ExpressionType.Equal: return " = ";
case ExpressionType.NotEqual: return " != ";
case ExpressionType.GreaterThan: return " > ";
case ExpressionType.GreaterThanOrEqual: return " >= ";
case ExpressionType.LessThan: return " < ";
case ExpressionType.LessThanOrEqual: return " <= ";
case ExpressionType.And: return " AND ";
case ExpressionType.AndAlso: return " AND ";
case ExpressionType.Or: return " OR ";
case ExpressionType.OrElse: return " OR ";
}
throw new NotSupportedException($"Operator not supported {nodeType}");
}
/// <summary>
/// Returns document field name for some type member
/// </summary>
private string ResolveMember(MemberInfo member, out MemberMapper memberMapper)
{
var name = member.Name;
// checks if parent field are not DbRef (checks for same dataType)
var isParentDbRef = _dbRefType != null && member.DeclaringType.IsAssignableFrom(_dbRefType);
// get class entity from mapper
var entity = _mapper.GetEntityMapper(member.DeclaringType);
entity.WaitForInitialization();
// get mapped field from entity
var field = entity.Members.FirstOrDefault(x => x.MemberName == name);View on GitHub (pinned to f906a5f850)
Solutions
- Avoid unsupported binary operators in LINQ queries; compute the value in memory and compare against a constant.
- For modulo or bitwise logic, fetch matching records with a broader predicate and filter in memory.
- Use a raw BsonExpression if the equivalent operation exists in BsonExpression syntax.
Example fix
// before -- modulo is not supported col.Find(x => x.Value % 2 == 0); // after -- precompute or filter in memory var results = col.FindAll().Where(x => x.Value % 2 == 0).ToList();
Defensive patterns
Strategy: validation
Validate before calling
// Avoid unsupported binary operators in LINQ queries // Supported: +, -, *, /, =, !=, >, >=, <, <=, AND, OR // Unsupported: %, ^, <<, >>, and checked variants var results = col.FindAll().Where(x => x.Value % 2 == 0).ToList();
Type guard
// Check that a binary expression uses only supported operators
static readonly HashSet<ExpressionType> SupportedOperators = new()
{
ExpressionType.Add, ExpressionType.Multiply, ExpressionType.Subtract, ExpressionType.Divide,
ExpressionType.Equal, ExpressionType.NotEqual, ExpressionType.GreaterThan,
ExpressionType.GreaterThanOrEqual, ExpressionType.LessThan, ExpressionType.LessThanOrEqual,
ExpressionType.And, ExpressionType.AndAlso, ExpressionType.Or, ExpressionType.OrElse
}; Try / catch
try
{
var results = col.Find(x => x.Value % 2 == 0);
}
catch (NotSupportedException ex) when (ex.Message.Contains("Operator not supported"))
{
results = col.FindAll().Where(x => x.Value % 2 == 0).ToList();
} Prevention
- Avoid modulo (%), bitwise XOR (^), and bit-shift (<<, >>) operators in LINQ queries.
- Precompute values that require unsupported operators and compare against constants.
- Familiarize yourself with the supported operator set: +, -, *, /, =, !=, >, >=, <, <=, AND, OR.
When it happens
Trigger: Using a binary operator not in the supported list: Modulo (%), ExclusiveOr (^), LeftShift (<<), RightShift (>>), Power, Coalesce (?? handled separately), ArrayIndex ([] handled separately), AddChecked, MultiplyChecked, etc. For example x => x.Value % 2 == 0.
Common situations: Using modulo, bitwise XOR, or bit-shift operations in LINQ queries. Using checked arithmetic (AddChecked, etc.) in debug builds or certain compiler configurations. Assuming all C# binary operators have BsonExpression equivalents.
Related errors
- 0
- Extend expression must return an anonymous class to be merge
- Expression {expr.ToString()} must be a lambda expression
- Extend expression must return a document. Eg: `col.UpdateMan
- Multiple OrderBy calls are not supported. Use ThenBy for add
AI-assisted analysis of litedb-org/LiteDB@f906a5f850 (2026-08-13).
Data as JSON: /api/errors/ce95091c3a56770a.
Report an issue: GitHub.