{"record":{"id":"0a02dd63432ebb92","repo":"mongodb/mongoid","slug":"invalid-criteria-for-estimated-count","errorCode":null,"errorMessage":"Invalid criteria for estimated_count.","messagePattern":"Invalid criteria for estimated_count\\.","errorType":"exception","errorClass":"Mongoid::Errors::InvalidEstimatedCountScoping","httpStatus":null,"severity":"error","filePath":"lib/mongoid/contextual/mongo.rb","lineNumber":98,"sourceCode":"          view.count(options)\n        end\n      end\n\n      # Get the estimated number of documents matching the query.\n      #\n      # Unlike count, estimated_count does not take a block because it is not\n      # traditionally defined (with a block) on Enumerable like count is.\n      #\n      # @example Get the estimated number of matching documents.\n      #   context.estimated_count\n      #\n      # @param [ Hash ] options The options, such as maxTimeMS to be factored\n      #   into the count.\n      #\n      # @return [ Integer ] The number of matches.\n      def estimated_count(options = {})\n        unless criteria.selector.empty?\n          raise Mongoid::Errors::InvalidEstimatedCountScoping.new(klass) if klass.default_scoping?\n\n          raise Mongoid::Errors::InvalidEstimatedCountCriteria.new(klass)\n\n        end\n        view.estimated_document_count(options)\n      end\n\n      # Delete all documents in the database that match the selector.\n      #\n      # @example Delete all the documents.\n      #   context.delete\n      #\n      # @return [ nil ] Nil.\n      def delete\n        view.delete_many.deleted_count\n      end\n      alias delete_all delete\n","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/contextual/mongo.rb#L80-L116","documentation":"Error \"Invalid criteria for estimated_count.\" thrown in mongodb/mongoid.","triggerScenarios":"Thrown at lib/mongoid/contextual/mongo.rb:98 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"}