Skip to content

Instantly share code, notes, and snippets.

@saberma
Created March 14, 2011 13:58
Show Gist options
  • Save saberma/869147 to your computer and use it in GitHub Desktop.
Save saberma/869147 to your computer and use it in GitHub Desktop.
The query result of embedded document is inconsistent.
require 'mongoid'
class Address
include Mongoid::Document
embeds_many :locations
end
class Location
include Mongoid::Document
field :name
embedded_in :address
end
Mongoid.configure.master = Mongo::Connection.new.db('mongoid-bug-2011-03-14')
@address = Address.new(:street => "Clarkenwell Road")
@address.locations << Location.new(:name => 'No.1')
@address.save
#just change the condition order, but the result is difference.
p @address.locations.where(:name.in => ['No.2'], :name.ne => nil ).first
p @address.locations.where(:name.ne => nil, :name.in => ['No.2']).first
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment