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

Mongoid matches? does not support $elemMatch

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 6.0.0
    • Affects Version/s: None
    • Component/s: None
    • None

      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

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

              Created:
              Updated:
              Resolved: