给定一个初始化日期和今天,搜索该日期之间的所有"名称"的查询是什么?
谢谢
MongoMapper
你应该能够使用MongoMapper的查询运算符。假设您有一个带有"created_on"日期的"用户"模型,您可以使用它来获取名称。(我相信MongoDB使用UTC时间来存储所有日期/时间对象):
initial_date = Time.utc(2011, 5, 1) # 2011-05-01 00:00:00 UTC
@users = User.where(:created_on => {:$gte => initial_date, :$lte => Time.now.utc})
@users.each do |user|
puts user.name
end
红宝石蒙戈司机
initial_date = Time.utc(2011, 5, 1) # 2011-05-01 00:00:00 UTC
@conn = Mongo::Connection.new
@db = @conn['my_db']
@collection = @db['users']
@users = @collection.find(:created_on => {:$gte => initial_date, :$lte => Time.now.utc})
@users.each do |user|
puts user['name']
end