给定一个初始日期和今天,在该日期之间搜索所有“名称”的查询是什么?
谢谢
MongoMapper
您应该能够使用 MongoMapper 的查询运算符。假设您有一个带有“created_on”日期的“用户”模型,您可以使用它来获取名称。(我相信 MongoDB 使用 UTC Times 来存储所有日期/时间对象):
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
Ruby Mongo 驱动程序
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