{"record":{"id":"c9353cc7a882efed","repo":"litedb-org/LiteDB","slug":"field-c9353c","errorCode":null,"errorMessage":"field","messagePattern":"field","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"LiteDB/Client/Structures/Query.cs","lineNumber":59,"sourceCode":"            return query;\n        }\n\n        /// <summary>\n        /// Returns all documents\n        /// </summary>\n        public static Query All(string field, int order = Ascending)\n        {\n            var query = new Query();\n            query.OrderBy.Add(new QueryOrder(BsonExpression.Create(field), order));\n            return query;\n        }\n\n        /// <summary>\n        /// Returns all documents that value are equals to value (=)\n        /// </summary>\n        public static BsonExpression EQ(string field, BsonValue value)\n        {\n            if (field.IsNullOrWhiteSpace()) throw new ArgumentNullException(nameof(field));\n\n            return BsonExpression.Create($\"{field} = {value ?? BsonValue.Null}\");\n        }\n\n        /// <summary>\n        /// Returns all documents that value are less than value (&lt;)\n        /// </summary>\n        public static BsonExpression LT(string field, BsonValue value)\n        {\n            if (field.IsNullOrWhiteSpace()) throw new ArgumentNullException(nameof(field));\n\n            return BsonExpression.Create($\"{field} < {value ?? BsonValue.Null}\");\n        }\n\n        /// <summary>\n        /// Returns all documents that value are less than or equals value (&lt;=)\n        /// </summary>\n        public static BsonExpression LTE(string field, BsonValue value)","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Client/Structures/Query.cs#L41-L77","documentation":"Query.EQ(string field, BsonValue value) builds a BsonExpression of the form '$field = $value' for an equality filter. At Query.cs:59 it throws ArgumentNullException(nameof(field)) whenever field is null, empty, or whitespace, because such a value cannot be interpolated into a valid BsonExpression and would later fail at parse time with a confusing error. LiteDB fails fast on the public API surface so the caller sees the real cause. The check uses IsNullOrWhiteSpace, so a string of spaces is treated the same as null.","triggerScenarios":"Calling Query.EQ(null, 1), Query.EQ(\"\", 1), or Query.EQ(\"   \", 1). Also when the field name is loaded from configuration, a dictionary lookup, or JSON deserialization that yields null/empty.","commonSituations":"Field name read from appsettings or an environment variable that was not set; a property name built dynamically (e.g. char-by-char or via a loop) that produced an empty string; a refactor that swapped argument order and passed the value where the field belongs.","solutions":["Pass a concrete non-empty document field path such as Query.EQ(\"_id\", id).","Guard the variable first: if (name.IsNullOrWhiteSpace()) return; before calling Query.EQ.","Centralize field names in constants so they can never silently become empty."],"exampleFix":"// before\nvar q = Query.EQ(fieldName, age); // fieldName may be null/empty\n\n// after\nif (string.IsNullOrWhiteSpace(fieldName))\n    throw new InvalidOperationException(\"fieldName must be supplied by the caller.\");\nvar q = Query.EQ(fieldName, age);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(field))\n    throw new ArgumentException(\"Field name is required.\", nameof(field));\nvar q = Query.EQ(field, value);","typeGuard":"static bool IsValidField(string field) => !string.IsNullOrWhiteSpace(field);","tryCatchPattern":null,"preventionTips":["Validate field names at the API/controller boundary before they reach the query layer.","Store document field names as constants so they cannot silently become empty.","Unit-test query builders with null and empty-string field inputs."],"tags":["litedb","query","argument-null","validation","field-name"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}