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

Inconsistent chaining criteria

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 12_01_17
    • Component/s: None
    • Labels:
      None

      Description

      So I have a use case where I chain multiple criteria together and it is possible that one criteria might contradict another. This is because thy operate independently.

      So I might end up with a chain that looks like this:
      Collection.not_in(:slug => ["some-slug"]).any_in(:slug => ["some-slug"])

      Which produces:
      <Mongoid::Criteria:0x1065f7808 @documents=[], @klass=Newsroom, @selector={:slug=>{"$in"=>["some-slug", "some-slug"]}}, @options={}>

      If the criteria were added in a different order, ie:
      Collection.any_in(:slug => ["some-slug"]).not_in(:slug => ["some-slug"])

      Mongoid produces this:
      <Mongoid::Criteria:0x1065cb370 @documents=[], @klass=Newsroom, @selector={:slug=>{"$nin"=>["some-slug", "some-slug"]}}, @options={}>

      These two queries produce inconsistent results. I would think that they should produce a mongo query that is the equivalent of:
      db.collections.find({slug:{$nin: ["some-slug"], $in: ["some-slug"]}})

      which produces the correct result of not showing the item with that slug

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            nader Nader Akhnoukh
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: