Mongodb查询语句

Posted yjq_叶

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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"}}
])

以上是关于Mongodb查询语句的主要内容,如果未能解决你的问题,请参考以下文章

MongoDB简单查询语句

MongoDB简单查询语句

mongodb 常用查询语句

mongodb 跟踪SQL语句及慢查询收集

mongodb常用查询语句

MongoDB常用28条查询语句