ugotchi
ugotchi

Reputation: 1013

mysql hour() method in mongodb?

Whats the simplest way of extracting the hour integer from a time string (format "23:21:00") in MongoDB?

hour("23:21:00") // 23

I have the function implemented and working in mysql, but it seems that its not that straightforward in Mongo.

Am I resigned to converting the time into a date object, and then using Mongo's $hour aggregation pipeline function?

Upvotes: 0

Views: 63

Answers (1)

archLucifer
archLucifer

Reputation: 389

Use the $where db.collection.find({$where : function() { return this.date.getHours() == 23} })

Upvotes: 1

Related Questions