[英]How do you query by Date and Date Range in Mongo
This would be the equivalent of this SQL statement? 这相当于这个SQL语句?
Select * from example WHERE date = '2011-09-21'
The record is stored with a MongoDate field. 该记录与MongoDate字段一起存储。
I would also like to know the syntax of the between query. 我还想知道查询之间的语法。
This would be the equivalent of this SQL statement?
这相当于这个SQL语句?
Select * from example WHERE date = '2011-09-21'
从例如WHERE date ='2011-09-21'中选择*
db.example.find({date: dateobject});
In the case of MongoDB + PHP, you'll want to use the [MongoDate][2]
class to represent those dates. 对于MongoDB + PHP,您将需要使用
[MongoDate][2]
类来表示这些日期。 Other language drivers typically just use the language date construct. 其他语言驱动程序通常只使用语言日期构造。
I would also like to know the syntax of the between query.
我还想知道查询之间的语法。
MongoDB does not have a between
clause. MongoDB没有
between
子句。
To use "Greater than" you will need to use one of the query operators. 要使用“大于”,您需要使用其中一个查询运算符。 See here for details.
详情请见此处 。 Simple example:
简单的例子:
db.example.find({ date: { $gt: lowdate, $lt: highdate } });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.