Skip to content

Bug: comments are indexed in mongodb #14

Description

@srilumpa

Hi,

I have encountered an issue with the creation of comments: when creating comments or updating its commentable resource, a MongoID exception raised saying that my operation failed with error 17280: "Btree::insert: key too large to index, failing my_db.my_commentable.$comments_1.

After some investigations, I found that the index comments_1 was created directly by mongoid_commentable in lib/mongoid/commentable.rb:

module Mongoid::Commentable
  extend ActiveSupport::Concern
  included do |base|
    base.embeds_many :comments, :as => :commentable
    if Gem::Version.new(Mongoid::VERSION) < Gem::Version.new('3.0.0')
      base.index [['comments', Mongo::ASCENDING]]
    else
      base.index 'comments' => 1 # Index created right here....
    end
  end

Why are you indexing the whole comment? Didn't you mean to index comment._id instead?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions