{"record":{"id":"15b8c5be481548d6","repo":"mongodb/mongoid","slug":"not-argument-cannot-be-an-empty-hash-errors-i","errorCode":null,"errorMessage":"$not argument cannot be an empty hash: #{Errors::InvalidQuery.truncate_expr(condition)}","messagePattern":"\\$not argument cannot be an empty hash: #(.+?)","errorType":"exception","errorClass":"Mongoid::Errors::InvalidQuery","httpStatus":null,"severity":"error","filePath":"lib/mongoid/matcher/not.rb","lineNumber":25,"sourceCode":"    # @api private\n    module Not\n      # Returns whether a value satisfies an $not expression.\n      #\n      # @param [ true | false ] exists Whether the value exists.\n      # @param [ Object ] value The value to check.\n      # @param [ Hash | Regexp | BSON::Regexp::Raw ] condition\n      #   The $not condition predicate.\n      #\n      # @return [ true | false ] Whether the value matches.\n      #\n      # @api private\n      module_function def matches?(exists, value, condition)\n        case condition\n        when ::Regexp, BSON::Regexp::Raw\n          !Regex.matches?(exists, value, condition)\n        when Hash\n          if condition.empty?\n            raise Errors::InvalidQuery, \"$not argument cannot be an empty hash: #{Errors::InvalidQuery.truncate_expr(condition)}\"\n          end\n\n          condition.all? do |(k, cond_v)|\n            k = k.to_s\n            unless k.start_with?('$')\n              raise Errors::InvalidQuery, \"$not arguments must be operators: #{Errors::InvalidQuery.truncate_expr(k)}\"\n            end\n\n            !FieldOperator.get(k).matches?(exists, value, cond_v)\n          end\n        else\n          raise Errors::InvalidQuery, \"$not argument must be a Hash or a regular expression: #{Errors::InvalidQuery.truncate_expr(condition)}\"\n        end\n      end\n    end\n  end\nend\n","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/matcher/not.rb#L7-L43","documentation":"Error \"$not argument cannot be an empty hash: #{Errors::InvalidQuery.truncate_expr(condition)}\" thrown in mongodb/mongoid.","triggerScenarios":"Thrown at lib/mongoid/matcher/not.rb:25 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0da0e23d71adfbad31128c18e5e2c8c301c6f7c4","analyzedAt":"2026-08-23T06:25:47.656Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}