Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document not found error with Mongoid #11

Open
heaven opened this issue Feb 24, 2012 · 2 comments
Open

Document not found error with Mongoid #11

heaven opened this issue Feb 24, 2012 · 2 comments

Comments

@heaven
Copy link

heaven commented Feb 24, 2012

Query processing is launched in loop with timeout in 30 seconds. It works great until some records from the mongoid model will not be deleted. After that all the queries fails and data will not be deleted from the index.

Document not found for class MongoDoc with id(s) 4f47a487d6194c6ac1000001, 4f47a488d6194c6ac1000008, 4f47a488d6194c6ac100000b, 4f47a488d6194c6ac1000010, 4f47a488d6194c6ac1000013, 4f47a489d6194c6ac1000018, 4f47a48ad6194c6ac100003c, 4f47a489d6194c6ac100001b, 4f47a489d6194c6ac1000024, 4f47a489d6194c6ac1000029, 4f47a489d6194c6ac100002e, 4f47a489d6194c6ac1000036, 4f47a48ad6194c6ac100003b, 4f47a48ad6194c6a
@bdurand
Copy link
Owner

bdurand commented Mar 1, 2012

How are the models not able to be deleted?

@heaven
Copy link
Author

heaven commented Mar 1, 2012

The problem is in the Sunspot::Mongoid::DataAccessor#load_all(ids) method. Finally it tries to load the records in this way

def load_all(ids)
  criteria(ids)
end

private

def criteria(id)
  @clazz.criteria.find(id)
end

But find raises error if records not found. This is reproducible in this way:

  1. Stop queue processing.
  2. Create few mongo db docs (so they will be queued for indexing).
  3. Delete these docs.
  4. Try to process the queue.

BTW, active record is more adequate in this case and doesn't raise the error. So, problem is completely in mongoid.

I have solved this issue in this way:

module Sunspot
  module Mongoid
    class DataAccessor
      def load_all(ids)
        @clazz.where(:_id.in => ids).to_a
      end
    end
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants