litedb-org/LiteDB · error · LiteException
0
0
Error message
Left expression `{left.Source}` returns more than one result. Try use ANY or ALL before operant. What it means
Thrown by the expression parser during binary-operator construction when the left operand is non-scalar (returns multiple values) and the operator is not prefixed with ALL/ANY. The parser requires multi-value left operands to use quantifiers (ANY/ALL) before comparison operators. This is a LiteException (code 0) thrown at parse time.
Source
Thrown at LiteDB/Document/Expression/Parser/BsonExpressionParser.cs:157
{
order++;
}
else
{
// get left/right values to execute operator
var left = values.ElementAt(n);
var right = values.ElementAt(n + 1);
var src = op.Value.Item1;
var method = op.Value.Item2;
var type = op.Value.Item3;
// test left/right scalar
var isLeftEnum = op.Key.StartsWith("ALL") || op.Key.StartsWith("ANY");
if (isLeftEnum && left.IsScalar) left = ConvertToEnumerable(left);
//if (isLeftEnum && left.IsScalar) throw new LiteException(0, $"Left expression `{left.Source}` must return multiples values");
if (!isLeftEnum && !left.IsScalar) throw new LiteException(0, $"Left expression `{left.Source}` returns more than one result. Try use ANY or ALL before operant.");
if (!isLeftEnum && !right.IsScalar) throw new LiteException(0, $"Left expression `{right.Source}` must return a single value");
if (right.IsScalar == false) throw new LiteException(0, $"Right expression `{right.Source}` must return a single value");
BsonExpression result;
// when operation is AND/OR, use AndAlso|OrElse
if (type == BsonExpressionType.And || type == BsonExpressionType.Or)
{
result = CreateLogicExpression(type, left, right);
}
else
{
// method call parameters
var args = new List<Expression>();
if (method?.GetParameters().FirstOrDefault()?.ParameterType == typeof(Collation))
{
args.Add(context.Collation);View on GitHub (pinned to f906a5f850)
Solutions
- Prefix the comparison with ANY or ALL: `$.tags ANY = 'x'`.
- Use the helper methods Query.Any / Query.All in the fluent API if building programmatically.
- Rewrite to use IN or array-contains semantics appropriate to the use case.
Example fix
// before
var docs = col.Query().Where("$.tags = 'x'").ToList();
// after
var docs = col.Query().Where("$.tags ANY = 'x'").ToList(); Defensive patterns
Strategy: validation
Validate before calling
// Before building the expression, check if left operand is scalar
if (!leftExpr.IsScalar)
throw new InvalidOperationException("Use ANY/ALL for multi-value left operands."); Type guard
static bool NeedsQuantifier(BsonExpression left) => !left.IsScalar;
Try / catch
try { col.Query().Where(whereClause).ToList(); }
catch (LiteException ex) when (ex.Message.Contains("more than one result"))
{ /* add ANY or ALL before the comparison operator */ } Prevention
- Always use ANY/ALL when comparing array fields.
- In query builders, detect array-typed fields and auto-insert quantifiers.
- Test where-clauses against array fields before deploying.
When it happens
Trigger: Writing a query like `$.tags = 'x'` where $.tags is an array field and no ANY/ALL quantifier is used. Comparing a multi-value path expression directly with =, >, <, etc.
Common situations: Querying array fields with direct comparison operators instead of using ANY/ALL. Copying SQL semantics where `array = value` has implicit ANY behavior. Query builder constructing expressions without quantifier awareness.
Related errors
AI-assisted analysis of litedb-org/LiteDB@f906a5f850 (2026-08-13).
Data as JSON: /api/errors/2098e36c07bca3c7.
Report an issue: GitHub.