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

Invalid operator $or

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

      I upgraded mongoid to version 3.0.21 and I got this error on this query:

      def delete_dependent_notifications
      notifications = Notification.any_of(

      {subject_id: Moped::BSON::ObjectId.from_string(self.id) , subject_type: self.class}

      ,

      {secondary_subject_id: Moped::BSON::ObjectId.from_string(self.id) , secondary_subject_type: self.class}

      )
      notifications.delete_all
      end

      Query:
      MOPED: 127.0.0.1:27017 QUERY database=trust_the_crowd_development collection=notifications selector={"$query"=>{"$or"=>[

      {"subject_id"=>"5113ee1be1054eb29b000007", "subject_type"=>"Comment"}

      ,

      {"secondary_subject_id"=>"5113ee1be1054eb29b000007", "secondary_subject_type"=>"Comment"}

      ]}, "$orderby"=>{"created_at"=>-1}}

      Processing by CommentsController#destroy as JS
      2013-02-08T02:53:13+00:00 app[web.1]: Parameters:

      {"question_id"=>"test-of-video-with-question-yet-again", "id"=>"5114688b046fa61f02000002"}

      2013-02-08T02:53:13+00:00 app[web.1]: Completed 500 Internal Server Error in 52ms
      2013-02-08T02:53:14+00:00 heroku[router]: at=info method=DELETE path=/questions/test-of-video-with-question-yet-again/comments/5114688b046fa61f02000002 host=staging.trustthecrowd.com fwd=190.244.143.70 dyno=web.1 queue=0 wait=0ms connect=5ms service=295ms status=500 bytes=2967
      2013-02-08T02:53:14+00:00 app[web.1]:
      2013-02-08T02:53:14+00:00 app[web.1]: Moped::Errors::OperationFailure (The operation: #<Moped::Protocol::Command
      2013-02-08T02:53:14+00:00 app[web.1]: @length=85
      2013-02-08T02:53:14+00:00 app[web.1]: @request_id=176
      2013-02-08T02:53:14+00:00 app[web.1]: @response_to=0
      2013-02-08T02:53:14+00:00 app[web.1]: @op_code=2004
      2013-02-08T02:53:14+00:00 app[web.1]: @flags=[]
      2013-02-08T02:53:14+00:00 app[web.1]: @full_collection_name="trustthecrowd-staging.$cmd"
      2013-02-08T02:53:14+00:00 app[web.1]: @skip=0
      2013-02-08T02:53:14+00:00 app[web.1]: @limit=-1
      2013-02-08T02:53:14+00:00 app[web.1]: @selector={:getlasterror=>1, :safe=>true}
      2013-02-08T02:53:14+00:00 app[web.1]: @fields=nil>
      2013-02-08T02:53:14+00:00 app[web.1]: failed with error 10068: "invalid operator: $or"
      2013-02-08T02:53:14+00:00 app[web.1]:
      2013-02-08T02:53:14+00:00 app[web.1]: See https://github.com/mongodb/mongo/blob/master/docs/errors.md
      2013-02-08T02:53:14+00:00 app[web.1]: for details about this error.):
      2013-02-08T02:53:14+00:00 app[web.1]: app/models/comment.rb:80:in `delete_dependent_notifications'
      2013-02-08T02:53:14+00:00 app[web.1]: app/controllers/comments_controller.rb:37:in `destroy'
      2013-02-08T02:53:14+00:00 app[web.1]: lib/middleware/canonical_host.rb:11:in `call'

      But there is no error when I run this query from Mongo console:

      db.notifications.remove({$or:[

      {"subject_id": ObjectId("5112fc6519bfad3e55000033"), "subject_type": "Comment"}

      ,

      {"secondary_subject_id": ObjectId("507a08258099ca0002000807"), "secondary_subject_type": "Comment"}

      ]})

      Thanks.
      Aldo.

            Assignee:
            Unassigned Unassigned
            Reporter:
            alduro alduro
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: