franklin stine
franklin stine

Reputation: 1110

Mongoid replacement for MySQL's DateTime field tools like select * from posts where HOUR(posted) = 01

I'm attempting to port a MySQL backed app to MongoDB with Mongoid. Some vital queries make use of MySQL's DateTime tools such as:

select * from posts where HOUR(posted) = 01

Where posted is a full DateTime timestamp. How can this be achieved using Mongoid?

Upvotes: 0

Views: 152

Answers (1)

Yanhao
Yanhao

Reputation: 5294

MongoDB uses Javascript internally. You can send a piece of Javascript code as filter:

posts = Post.where("this.posted.getHours() == 1")

Upvotes: 1

Related Questions