-
-
Save dougalcorn/1453503 to your computer and use it in GitHub Desktop.
$in criteria in Mongoid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
irb(main):062:0> base.in(:from_id => port_ids) | |
=> #<Mongoid::Criteria | |
selector: {:from_id=>"$in0d06b030-04d8-012f-18e7-388d1201202c5b932da1-04d8-012f-b944-388d1201202c"}, | |
options: {}, | |
class: Ccom::PortConnection, | |
embedded: false> | |
# that's a jacked up selector | |
# now not using the _id on the field name | |
irb(main):061:0> base.in(:from => port_ids) | |
=> #<Mongoid::Criteria | |
selector: {:from=>{"$in"=>["0d06b030-04d8-012f-18e7-388d1201202c", "5b932da1-04d8-012f-b944-388d1201202c"]}}, | |
options: {}, | |
class: Ccom::PortConnection, | |
embedded: false> | |
# the selector is no longer jacked |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
irb(main):057:0> port_ids = ["0d06b030-04d8-012f-18e7-388d1201202c", "5b932da1-04d8-012f-b944-388d1201202c"] | |
=> ["0d06b030-04d8-012f-18e7-388d1201202c", "5b932da1-04d8-012f-b944-388d1201202c"] | |
irb(main):058:0> base = Mongoid::Criteria.new(Ccom::PortConnection) | |
=> #<Mongoid::Criteria | |
selector: {}, | |
options: {}, | |
class: Ccom::PortConnection, | |
embedded: false> | |
irb(main):059:0> base.any_in("from_id" => port_ids).to_a | |
=> [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MONGODB mimosa2_development['ccom_entities'].find({"from_id"=>"$in0d06b030-04d8-012f-18e7-388d1201202c5b932da1-04d8-012f-b944-388d1201202c", :_type=>{"$in"=>["Ccom::PortConnection"]}}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment