Dynamoid
Dynamoid copied to clipboard
query by range no results
Hi, I have a model called StatDisplayDynamo
class StatDisplayDynamo
include Dynamoid::Document
table :name => :stat_display_dynamo, :key => :id, :read_capacity => 400, :write_capacity => 400
field :campaign_id, :integer
field :ip_address
field :ua_raw
field :ua_name
field :ua_version
field :ua_engine
field :ua_os
field :ua_engine_version
index :created_at, :range => true
belongs_to :company
end
with one entry in
StatDisplayDynamo.all => [#<StatDisplayDynamo:0x00000104dc2c38 @new_record=false, @attributes={:created_at=>Tue, 06 Aug 2013 20:55:21 +0200, :updated_at=>Tue, 06 Aug 2013 20:55:21 +0200, :id=>"b9b769e7-bdb7-4225-8215-842caaa1652c", :campaign_id=>114, :ip_address=>"127.0.0.1", :ua_raw=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:22.0) Gecko/20100101 Firefox/22.0", :ua_name=>"Unknown", :ua_version=>nil, :ua_engine=>"gecko", :ua_os=>"OS X 10.8", :ua_engine_version=>"20100101", :company_ids=>nil}, @associations={}, @changed_attributes={}>]
but if I query in this way
StatDisplayDynamo.where("created_at.gt" => DateTime.now-2.hours).all
when
DateTime.now-2.hours => Tue, 06 Aug 2013 19:34:24 +0200
I get no result. Where am i wrong?
Same issue here, any progress from your end?
I think it's because you made created at an index which converted that field to be a string instead of a diatomite. Hence your datetime is no longer "greater_than" the datetime in the record since it has the "#" appended in front for some reason.
if I do "#Tue, 06 Aug 2013 20:55:21 +0200" > "Tue, 06 Aug 2013 19:34:24 +0200" I get false
What does StatDisplayDynamo.where("created_at.gt" => ("#" + DateTime.now-2.hours.to_s).all give you just to test this theory?