[英]Querying a date range in MongoDB with tweets in PHP
I have documents stored in MongoDB with each documents containing a "created_at" that looks like this: 我有存储在MongoDB中的文档,每个文档都包含一个如下所示的“ created_at”:
"created_at" : "Wed Jan 24 15:25:20 +0000 2018"
I couldn't do a range query with a format like this. 我无法使用这种格式进行范围查询。 Should I update all of the documents and convert them into readable dates? 我应该更新所有文档并将其转换为可读日期吗? Or is there a way in PHP where I should just convert the dates inside the PHP without updating/harming the documents inside MongoDB. 还是在PHP中有一种方法,我应该只在PHP中转换日期而不更新/损坏MongoDB中的文档。 The latter seems to be more sensible since I am constantly feeding my database with streams of tweets everyday. 后者似乎更明智,因为我每天都在不断向我的数据库提供推文流。
You should reconsider the format you are using to store the created_at
timestamp. 您应该重新考虑用于存储created_at
时间戳的格式。 I would recommend to convert this data to ISODate
(js)/ MongoDB\\BSON\\UTCDateTime
(php). 我建议将这些数据转换为ISODate
(js)/ MongoDB\\BSON\\UTCDateTime
(php)。
Using this format, you can do range queries in your MongoDB without heavy lifting on your php side. 使用这种格式,您可以在MongoDB中进行范围查询,而不会在php方面造成麻烦。
Converting the data includes the following steps: 转换数据包括以下步骤:
Some relevant links: 一些相关链接:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.