Mongodb查询语句

db.getCollection('RpcMonitor_Request').find(
{
"RequestStartTime" :
{
$gt :ISODate("2018-05-14 02:00"),
$lt:ISODate("2018-05-14 04:00")
},
"_id":ObjectId("5af8fc5809d8d057f6a734e4")
})


db.getCollection('RpcMonitor_Request').aggregate(
[
{
$group:
{
RequestCount:{$sum:1},
_id:
{
"RequestDay": { $dateToString: { format: "%Y-%m-%d", date: "$RequestStartTime" } },
"RequestTypeName":"$RequestTypeName",
"RequestMethodName":"$RequestMethodName"
}
}
}
])

db.getCollection('RpcMonitor_Request').aggregate(
[
{
$group:
{
RequestCount:{$sum:1},
_id:
{
"RequestDay": { $dateToString: { format: "%Y-%m-%d", date: "$RequestStartTime" } },
"RequestTypeName":"$RequestTypeName",
"RequestMethodName":"$RequestMethodName"
}
}
},
{ $project : {"_id": 0, "RequestDay" : "$_id.RequestDay", "RequestTypeName" : "$_id.RequestTypeName", "count" : "$RequestCount","RequestMethodName":"$_id.RequestMethodName"}}
])


db.getCollection('RpcMonitor_Request').aggregate(
[
{$match:{
"RequestStartTime" :
{
$gt :ISODate("2018-05-14 02:00"),
$lt:ISODate("2018-05-14 04:00")
}
}},
{
$group:
{
RequestCount:{$sum:1},
_id:
{
"RequestDay": { $dateToString: { format: "%Y-%m-%d", date: "$RequestStartTime" } },
"RequestTypeName":"$RequestTypeName",
"RequestMethodName":"$RequestMethodName"
}
}
},
{ $project : {"_id": 0, "RequestDay" : "$_id.RequestDay", "RequestTypeName" : "$_id.RequestTypeName", "count" : "$RequestCount","RequestMethodName":"$_id.RequestMethodName"}}
])

 

var group = new BsonDocument
{
{ "_id", new BsonDocument
{
{ "Month", new BsonDocument("$month", "$RequestStartTime") },
{ "Day", new BsonDocument("$dayOfMonth", "$RequestStartTime") },
{ "Year", new BsonDocument("$year", "$RequestStartTime") },
{ "RequestMethodName", "$RequestMethodName" },
{ "RequestTypeName", "$RequestTypeName" },
{ "IsSuccess", "$IsSuccess" },
}
},
{ "Count", new BsonDocument("$sum", 1) } };
var project = new BsonDocument
{
{
"_id",0
},
{
"RequestMethodName","$_id.RequestMethodName"
},
{
"RequestTypeName","$_id.RequestTypeName"
},
{
"IsSuccess","$_id.IsSuccess"
},
{
"TotalCount","$Count"
}
};

 

 

var group = new BsonDocument
{
{ "_id", new BsonDocument
{
{ "RequestTime",new BsonDocument{
{
"$dateToString",new BsonDocument{
{ "format","%Y-%m-%d %H:%M"},
{"date", "$RequestStartTime" }
}
}
} },
{ "Day", new BsonDocument("$dayOfMonth", "$RequestStartTime") },
{ "Year", new BsonDocument("$year", "$RequestStartTime") },
{ "RequestMethodName", "$RequestMethodName" },
{ "RequestTypeName", "$RequestTypeName" },
{ "IsSuccess", "$IsSuccess" },
}
},
{ "Count", new BsonDocument("$sum", 1) } };

转载于:https://www.cnblogs.com/yjq-code/p/9035644.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值