Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-4098

Strange behaviour of models count

    • Type: Icon: Task Task
    • Resolution: Done
    • 5.0.1
    • Affects Version/s: None
    • Component/s: None
    • None

      I don't know how to reproduce this but on production server I have following in irb

      irb(main):058:0> Product.count
      => 0
      irb(main):059:0> Product.count
      => -1
      irb(main):060:0> Product.all.first
      => #<Product _id: 5584875f69702d4cf6000003, created_at: nil, updated_at: nil, title: nil, description: nil, slug: nil, dealership_type: nil, dealership_id: nil, external_version: nil, build_version: nil, content_zone: nil, external_id: nil, price: nil, price_rent: nil, price_negotiable: false, used: false, location: nil, photos: nil, specs: nil, category: nil>
      irb(main):061:0> Product.count
      => 0
      irb(main):062:0> Product.count
      => -1
      

      I have replica set there. Can you check the code, when this is possible? I have no extension on this model.

      require 'money'
      class Product
        include Mongoid::Document
        include Mongoid::Timestamps
      
        field :title,             type: String
        field :description,       type: String
        field :slug,       type: String
      
        field :dealership_type,   type: String
        field :dealership_id,     type: String
        field :external_version,  type: String
        field :build_version,     type: String
        field :content_zone,      type: String
        
        field :external_id,       type: String
      
        field :price,             type: Money
        field :price_rent,        type: Money
        field :price_negotiable,  type: Boolean, default: false
        field :used,              type: Boolean, default: false
        field :location,          type: String
      
        field :photos,            type: Array
        field :specs,             type: Array
        field :category,          type: String
      
        validates :category, :title, presence: true
        
        index({build_version: 1, dealership_type: 1, dealership_id: 1, external_id: 1})
        index({build_version: 1})
      end
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            rkyrychuk rkyrychuk
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: