Resque Worker: Invalid statement: $ oid

An employee who worked a few days ago stops working for some reason.

Resque log reports exception Mongo::OperationFailurewith errorinvalid operator: $oid

class SimilarTargets
  @queue = :similar_queue

  def self.perform(target_id)
    source_target = Target.find(target_id)

    ....

  end
end

The worker does not work with Target.find (target_id), even when a straight line is passed through the rails console.

Target.find (id) works fine in the console and elsewhere in the code, and I cannot understand why this happened, although the working class never changed last week.

+5
source share
2 answers

Have you recently updated Mongoid? The error makes this sound like the .find () method gets something like {"$oid": "[STRING]"}, which is a strict json representation of the object identifier for Mongo.

- , , :

target_id = target_id["$oid"] unless target_id.is_a?(String)
+7

- , Moped:: BSON:: ObjectId . .

Resque.enqueue(MyJob, @mongoid_instance.class.to_s, @mongoid_instance.id.to_s)
+1

All Articles