Skip to content

Instantly share code, notes, and snippets.

@CoralineAda
Created June 10, 2013 20:33
Show Gist options
  • Save CoralineAda/5752028 to your computer and use it in GitHub Desktop.
Save CoralineAda/5752028 to your computer and use it in GitHub Desktop.
Fill in missing daily records in a time-series query against a Mongo datastore using Mongoid.
activities = Activity.where(:date.gte => dates.first, :date.lte => dates.last)
((Date.today - 60.days)..Date.today).map do |date|
activities.where(:date.gte => date.beginning_of_day, :date.lte => date.end_of_day).first || Activity.new(:date => date, :stat => 0)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment