{"record":{"id":"3bdf7243512576c4","repo":"litedb-org/LiteDB","slug":"at-least-two-query-should-be-passed","errorCode":null,"errorMessage":"At least two Query should be passed","messagePattern":"At least two Query should be passed","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"LiteDB/Client/Structures/Query.cs","lineNumber":206,"sourceCode":"        public static QueryAny Any() => new QueryAny();\n\n        /// <summary>\n        /// Returns document that exists in BOTH queries results. If both queries has indexes, left query has index preference (other side will be run in full scan)\n        /// </summary>\n        public static BsonExpression And(BsonExpression left, BsonExpression right)\n        {\n            if (left == null) throw new ArgumentNullException(nameof(left));\n            if (right == null) throw new ArgumentNullException(nameof(right));\n\n            return $\"({left.Source} AND {right.Source})\";\n        }\n\n        /// <summary>\n        /// Returns document that exists in ALL queries results.\n        /// </summary>\n        public static BsonExpression And(params BsonExpression[] queries)\n        {\n            if (queries == null || queries.Length < 2) throw new ArgumentException(\"At least two Query should be passed\");\n\n            var left = queries[0];\n\n            for (int i = 1; i < queries.Length; i++)\n            {\n                left = And(left, queries[i]);\n            }\n\n            return left;\n        }\n\n        /// <summary>\n        /// Returns documents that exists in ANY queries results (Union).\n        /// </summary>\n        public static BsonExpression Or(BsonExpression left, BsonExpression right)\n        {\n            if (left == null) throw new ArgumentNullException(nameof(left));\n            if (right == null) throw new ArgumentNullException(nameof(right));","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Client/Structures/Query.cs#L188-L224","documentation":"Query.And(params BsonExpression[] queries) folds many filters with AND. At Query.cs:206 it throws ArgumentException(\"At least two Query should be passed\") when queries is null or has fewer than two elements, because AND is a binary operation that needs at least two operands. Passing a single filter or none is a usage error, not a null-element problem. This is an ArgumentException, not ArgumentNullException.","triggerScenarios":"Calling Query.And(), Query.And(single), Query.And(arr) where arr.Length < 2, or Query.And(null). A null array also triggers it (the check uses ||).","commonSituations":"Dynamically collecting filters from a request where only one (or zero) was provided; passing a list whose Count was not checked before folding.","solutions":["Guard the collection: if fewer than 2 filters, return the single one (or Query.All) instead of calling And.","Use the binary Query.And(left, right) when you know there are exactly two.","Ensure at least two non-null elements are passed."],"exampleFix":"// before\nvar q = Query.And(filters.ToArray()); // filters may have 0 or 1 element\n\n// after\nvar q = filters.Count switch\n{\n    0 => Query.All(),\n    1 => filters[0],\n    _ => Query.And(filters.ToArray())\n};","handlingStrategy":"validation","validationCode":"var q = filters.Count switch\n{\n    0 => Query.All(),\n    1 => filters[0],\n    _ => Query.And(filters.ToArray())\n};","typeGuard":"static bool CanFold(IReadOnlyList<BsonExpression> q) =>\n    q is not null && q.Count >= 2 && q.All(x => x is not null);","tryCatchPattern":null,"preventionTips":["Check the filter count before folding with the params overload.","Use the binary And(left, right) when exactly two operands are known.","Ensure no null elements sneak into the array (they throw at the binary overload)."],"tags":["litedb","query","argument","validation","and","composition"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}