Skip to content

Instantly share code, notes, and snippets.

@tpitale
Forked from fj/gist:660258
Created November 2, 2010 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tpitale/660264 to your computer and use it in GitHub Desktop.
Save tpitale/660264 to your computer and use it in GitHub Desktop.
ruby-1.8.7-p299 > class Vehicle
ruby-1.8.7-p299 ?> include Mongoid::Document
ruby-1.8.7-p299 ?> field :horsepower
ruby-1.8.7-p299 ?> field :top_speed_mph
ruby-1.8.7-p299 ?> end
=> nil
ruby-1.8.7-p299 > Vehicle.new(:horsepower => 300, :top_speed_mph => 180).save
=> true
ruby-1.8.7-p299 > Vehicle.new(:horsepower => 350, :top_speed_mph => 185).save
=> true
ruby-1.8.7-p299 > Vehicle.find(:all).count
=> 2
ruby-1.8.7-p299 > Vehicle.where(:horsepower.gt => 299, :top_speed_mph.ne => 180)
=> [#<Vehicle _id: 4cd07637aca25f5746000001, top_speed_mph: "180", horsepower: "300">,#<Vehicle _id: 4cd07637aca25f5746000002, top_speed_mph: "185", horsepower: "350">]
# I was not expecting to get back any records with the top_speed_mph of 180
# The first condition always works in another case in which the conditions are reversed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment