1-
//group by with match
db.ASSETS.aggregate([
{ "$match": {'categories':{'$in':['CTG513']}} },
{
"$group": {
"_id": {
"synopsis": "$synopsis"
},
"name":{"$first":"$_id"},
"total": { "$sum": 1 },
"type":{"$first":"$type"} ,
"code":{"$first":"$code"}
}
},
{ "$match": { "total": {'$gt':1}} },
{
"$project": {
"_id": 1,
"synopsis": "$_id.synopsis",
"type":1,
"name":1,
"code":1
}
}
])
2. https://www.cyberciti.biz/faq/how-to-secure-mongodb-nosql-production-database/
//group by with match
db.ASSETS.aggregate([
{ "$match": {'categories':{'$in':['CTG513']}} },
{
"$group": {
"_id": {
"synopsis": "$synopsis"
},
"name":{"$first":"$_id"},
"total": { "$sum": 1 },
"type":{"$first":"$type"} ,
"code":{"$first":"$code"}
}
},
{ "$match": { "total": {'$gt':1}} },
{
"$project": {
"_id": 1,
"synopsis": "$_id.synopsis",
"type":1,
"name":1,
"code":1
}
}
])
2. https://www.cyberciti.biz/faq/how-to-secure-mongodb-nosql-production-database/
//Daily Hunt Log
db.packages.aggregate([{$match:{"streaming_mode" : "dailyhunt_digivive_offdeck",asset_code:{$ne:'',$ne:null},record_date:{"$gte":
new Date('2018-02-22T00:00:00Z'),"$lte":
new Date('2018-02-28T00:00:00Z')}}},{$group:{_id
:{"asset_code":"$asset_code","paid_status":"$paid_status"},total_hits:{$sum:1},duration:{$sum:'$duration'},asset_code:{$first:'$asset_code'},channel_content:{$first:'$channel_content'},broadcaster:{$first:'$broadcaster'},content_type:{$first:'$content_type'},language:{$first:'$language'},genre:{$first:'$genre'}}},{$sort:{'total_hits':-1}}]);
No comments:
Post a Comment