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) } };

posted @ 2018-05-14 13:23  yjq_net  阅读(241)  评论(0编辑  收藏  举报