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

Mongoid matches? does not support $elemMatch

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 6.0.0
    • Component/s: None
    • Labels:
      None

      Description

      class Subdoc
        include Mongoid::Document
        embedded_in :foo
        field :a
        field :b
      end
      class Foo
        include Mongoid::Document
        embeds_many :subdocs
      end
       
      f = Foo.new
      f.subdocs.new(:a => 1, :b => 1)
       
      f.subdocs.where(:a => 1).first
      => #<Subdoc _id: 57912b932774e24d68ce123f, a: 1, b: 1>
       
      f.subdocs.where(:$elemMatch => {:a => 1}).first
      => nil
      

      I know that matches? isn't a full implementation of the MongoDB query evaluation engine, but this is fairly easy to support:

      https://github.com/mongodb/mongoid/pull/4300

        Attachments

          Activity

            People

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            jonhyman Jon Hyman
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: