- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章JavaScript按日期查询MongoDB中的数据的要点示例由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
group by date 聚合查询日期 统计每天数据(信息量) 1 。
1
2
3
4
5
|
{
"_id" : ObjectId("557ac1e2153c43c320393d9d"),
"msgType" : "text",
"sendTime" : ISODate("2015-06-12T11:26:26.000Z")
}
|
2 。
1
2
3
4
5
|
{
"_id" : ObjectId("557ac1ee153c43c320393d9e"),
"msgType" : "text",
"sendTime" : ISODate("2015-06-12T11:26:38.000Z")
}
|
3 。
1
2
3
4
5
|
{
"_id" : ObjectId("557ac2012de5d32d213963b5"),
"msgType" : "text",
"sendTime" : ISODate("2015-06-12T11:26:56.000Z")
}
|
4 。
1
2
3
4
5
|
{
"_id" : ObjectId("557ac978bb31196e21d23868"),
"msgType" : "text",
"sendTime" : ISODate("2015-06-12T11:58:47.000Z")
}
|
5 。
1
2
3
4
5
|
{
"_id" : ObjectId("557ac9afbb31196e21d23869"),
"msgType" : "text",
"sendTime" : ISODate("2015-06-12T11:59:43.000Z")
}
|
SQL Here 。
1
2
3
4
5
6
7
|
db.getCollection(
'wechat_message'
).aggregate(
[
{ $project : {
day
: {$substr: [
"$sendTime"
, 0, 10] }}},
{ $
group
: { _id :
"$day"
, number : { $
sum
: 1 }}},
{ $sort : { _id : -1 }}
]
)
|
Result Here 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
"result"
: [
{
"_id"
:
"2015-07-06"
,
"number"
: 13.0000000000000000
},
{
"_id"
:
"2015-07-05"
,
"number"
: 3.0000000000000000
},
{
"_id"
:
"2015-07-03"
,
"number"
: 10.0000000000000000
},
{
"_id"
:
"2015-07-02"
,
"number"
: 29.0000000000000000
},
]
|
查询某一天所有信息的3种方法,根据日期查询 mongodb的查询真让人难以琢磨,就查询单天信息,都需要花费一番功夫才行。 第一种方式: 。
1
2
3
4
|
coll.aggregate([
{$project:{sendDate: {$substr: [
'$sendTime'
, 0, 10]}, sendTime: 1, content:1}},
{$match:{sendDate:
'2015-07-05'
}},
])
|
第二种方式(第一种的变异): 。
1
2
|
coll.aggregate([
{$match: {
'sendTime'
: {
'$gte'
:
new
Date(
'2015-07-05'
),
'$lt'
:
new
Date(
'2015-07-06'
)}}}
|
第三中方式(第二种的变异): 。
1
2
|
coll.aggregate([
{$match: {
'sendTime'
: {
'$gte'
:
new
Date(
'2015-07-05 00:00:00'
),
'$lte'
:
new
Date(
'2015-07-05 23:59:59'
)}}}
|
查询结果如下(展示一种方式:其他展示略有不同): 。
1
2
3
|
[ { _id: 5599b09bc16aac90e9fb7995, sendDate: '2015-07-05' },
{ _id: 5599b161c16aac90e9fb7996, sendDate: '2015-07-05' },
{ _id: 5599b161c16aac90e9fb7997, sendDate: '2015-07-05' } ]
|
最后此篇关于JavaScript按日期查询MongoDB中的数据的要点示例的文章就讲到这里了,如果你想了解更多关于JavaScript按日期查询MongoDB中的数据的要点示例的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
为了将来自Github的很长的Gists嵌入到Wordpress博客中,什么代码将允许我设置高度,以便生成垂直滚动条? 500px左右的东西将是完美的。 编辑:现在已经解决了该问题,但是我花了很多时间
我有一些 Github 要点,我正在向潜在雇主展示我的编码风格。我确实相信我所有的 github 要点都是公开的,因为这就是我选择制作它们的方式。但是在访问 gist.github.com/myuse
我不知道这是否存在,但我希望能够做到: $ cat mygist.js | gh new gist 并让它返回 URL(并可能将其复制到剪贴板/在浏览器中打开它)。 最佳答案 似乎 GitHub 有一
我在没有登录的情况下意外创建了一个 secret 要点(我认为我的 session 在正确的时间过期了)..无论如何都要删除它..因为它包含敏感数据。 最佳答案 Update 04/08/2014 现
我想显示一个无序列表,其中包含 url 并相互缩进(但所有行都对齐/向左) * line one text text ted more text text text * line two te
我正在开发一个使用 Web Essentials 来捆绑和缩小脚本文件的项目。 它运行良好,当我保存对脚本文件的更改时,Web Essentials 会运行。我们目前有几个开发人员参与该项目,每次从源
我有以下限制: ALTER TABLE my_table ADD CONSTRAINT no_overlap EXCLUDE USING gist ( product_id WITH =,
我正在尝试从 python 程序更新要点中已创建的 json 文件。问题是,我不知道该怎么做。 我找到了this api ,我很确定这与我想做的事情有关。我再次不知道如何正确使用它。 我还发现了一个名
我正在尝试创建一个包含多行内容的要点,但不确定最好的方法。\n 不工作,也没有添加两个空行。它显示为单行文本。 var content = 'content on\nnewline here'; $.
Angular 会忽略其模板中的 script 标签,但它们是加载 GitHub gist 所必需的。这样做的最佳做法是什么?使用 iframe?动态创建 script 标签?还是别的? 最佳答案 一
我在使用 jQuery.ajax() 将要点发布到 Github 时遇到问题。要点已创建,响应为 201 Created,但 Firebug 中的响应选项卡为空,并且命中了错误回调。 var da
我看到了以下帖子:Sexy Code Snippet Management With Gists作者:Jeffrey Way,描述了如何在 Sublime Text 2 中使用 GitHub 管理和共
6.3.1.1p2说 The following may be used in an expression wherever an int or unsigned int may be used: A
我是一名优秀的程序员,十分优秀!