Friday, 22 April 2022

Php Questions

//Mongo ISO date and time $asset['insert_time']->toDateTime()->format('d/m/Y') ; // connect_error) { die("Connect Error (" . $mysqli->connect_errno . ") " . $mysqli->connect_error); } echo "

Connection OK ". $mysqli->host_info."

"; echo "

Server ".$mysqli->server_info."

"; echo "

Initial charset: ".$mysqli->character_set_name()."

"; $mysqli->close(); */ /* $array="{$match: { parent_id: 0 }}, {$sort: { _id: 1 }}, {$addFields: { parent_id: { $toString: '$_id' } }}, {$lookup: { from: 'PAYMENTMODES', localField: 'parent_id', foreignField: 'parent_id', as: 'data' }}, {$addFields: { final_data: { $map: { input: '$data', as: 'g', 'in': { k: '$$g.title', v: { is_recurring: '$$g.is_recurring', image: '$$g.image' } } } } }}, {$replaceRoot: { newRoot: { $arrayToObject: { $concatArrays: [ [ { k: '$title', v: { $arrayToObject: { $concatArrays: [ [ { k: 'is_recurring', v: '$is_recurring' }, { k: '$title', v: { $arrayToObject: { $concatArrays: [ '$final_data' ] } } } ] ] } } } ] ] } } }}"; echo JSON.parse($array); */ //echo "111"; die; /* $numbers = array(1,3,2,5,2); $array_size = count($numbers); echo "Numbers before sort: "; for ( $i = 0; $i < $array_size; $i++ ) echo $numbers[$i]; echo "n"; for ( $i = 0; $i < $array_size; $i++ ) { for ($j = 0; $j < $array_size; $j++ ) { if ($numbers[$i] < $numbers[$j]) { $temp = $numbers[$i]; $numbers[$i] = $numbers[$j]; $numbers[$j] = $temp; } } } echo "Numbers after sort: "; for( $i = 0; $i < $array_size; $i++ ) echo $numbers[$i]; echo "n"; */ /* $strname="manoj"; $string = "JAVATPOINT"; $length = strlen($string); for ($i=($length-1) ; $i >= 0 ; $i--) { echo $string[$i]; } */ //JWT Decode //you can use this one line to decode the jwt token /* $token = "your encrypted token goes here"; print_r(json_decode(base64_decode(str_replace('_', '/', str_replace('-','+',explode('.', $token)[1]))))); $here= "/a/b/c/d"; //list($i1,$i2,$i3,$i4)= explode('/',$here); //print "$i3"; for($i=1;$i<20;$i++) print ($i); */ //$arr1 = array(1,2,4,5,7); $arr1= [40,41,42,43,44,45,1,2,3,4,5,6,7,8,9,10,11,12,13,14,35,36,37,38,39,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,67,68,69,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34]; // construct a new array:1,2....max(given array). //echo max($arr1); die; $arr2 = range(1,max($arr1)); echo "
";
//print_r($arr2);                                                  

// use array_diff to get the missing elements 
$missing = array_diff($arr2,$arr1); // (3,6)

//print_r($missing); die;

$InputArray = array(1,2,4,5,7); 

// $largeInput = [40,41,42,43,44,45,1,2,3,4,5,6,7,8,9,10,11,12,13,14,35,36,37,38,39,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,67,68,69,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34];

$largeInput = [1,10,11,3,89,15,20,23,32,43,45,41,65,12,];
$missingIds = [];
$min = 0;
$max = 0;
$chunkSize = 10;
$chunkNo = 0;
 $currentInput = array_slice($largeInput, $chunkNo, $chunkSize);
 //print_r($currentInput); die;
while(count($currentInput) > 0) {
    foreach($currentInput as $id) {
        if(in_array($id,$missingIds)) {
            $missingIds = array_diff($missingIds,[$id]);
            continue;
        }
        if($id <= $min) {
            $distMin = $min - $id;
            if($distMin > 2) {
                $tempArr = range($id+1,$min-1);
                $missingIds = array_merge($missingIds, $tempArr);
                $tempArr = [];
            } else if ($distMin > 1) {
                $tempArr = [$id+1];
                $missingIds = array_merge($missingIds, $tempArr);
                $tempArr = [];
            } 
            $min = $id;
        } else if ($id >= $max){
            $distMax = $id - $max;
            if($distMax > 2) {
                $tempArr = range($max+1,$id-1);
                $missingIds = array_merge($missingIds, $tempArr);
                $tempArr = [];
            } else if ($distMax > 1) {
                $tempArr = [$max+1];
                $missingIds = array_merge($missingIds, $tempArr);
                $tempArr = [];
            } 
            $max = $id;
        }   
    }
    $chunkNo++;
    $currentInput = array_slice($largeInput, $chunkNo, $chunkSize);
}
//print_r($missingIds);

//curl -XPUT "http://localhost:9200/my_index/_settings" -d '{ "index" : { "max_result_window" : 500000 } }' -H "Content-Type: application/json"

$a=10;
$b=20;
$a=$a+$b;
$b=$a-$b;
$a=$a-$b;



echo $a;
echo "
"; echo $b; //=======================================similar================= /* function similar(a,b) { var equivalency = 0; var minLength = (a.length > b.length) ? b.length : a.length; var maxLength = (a.length < b.length) ? b.length : a.length; for(var i = 0; i < minLength; i++) { if(a[i] == b[i]) { equivalency++; } } var weight = equivalency / maxLength; return (weight * 100) + "%"; } alert(similar("test","tes")); // 75% alert(similar("test","test")); // 100% alert(similar("test","testt")); // 80% alert(similar("test","tess")); // 75% */ //=========================================================================== $strRec="manoj tiwari"; for($i=strlen($strRec)-1;$i>=0;$i--){ //echo $i; echo $strRec[$i]; } echo "
"; $a=[5,3,2,18,9]; for($i=0;$i"; //Print star Trangile for($i=0;$i<=5;$i++){ for($j=0;$j<=$i;$j++){ echo "*"; } echo "
"; } echo "
"; for($i=0;$i<=5;$i++){ for($j=5-$i;$j>0;$j--){ echo "*"; } echo "
"; } echo "
"; for($i=1;$i<=5;$i++){ for($j=1;$j<=5-$i;$j++){ echo "  "; } for($k=1;$k<=$i;$k++){ echo "*  "; } echo "
"; }

Wednesday, 2 February 2022

rootReplace in mongoDB

//root replace in mongodb [ { '$match': { 'parent_id': 0 } }, { '$addFields': { 'parent_id': { '$toString': '$_id' } } }, { '$lookup': { 'from': 'PAYMENTMODES', 'localField': 'parent_id', 'foreignField': 'parent_id', 'as': 'data' } }, { '$addFields': { 'final_data': { '$map': { 'input': '$data', 'as': 'g', 'in': { 'k': '$$g.title', 'v': { 'is_recurring': '$$g.is_recurring', 'image': '$$g.image' } } } } } }, { '$replaceRoot': { 'newRoot': { '$arrayToObject': { '$concatArrays': [ [ { 'k': '$title', 'v': { '$arrayToObject': { '$concatArrays': [ [ { 'k': 'is_recurring', 'v': '$is_recurring' }, { 'k': '$title', 'v': { '$arrayToObject': { '$concatArrays': [ '$final_data' ] } } } ] ] } } } ] ] } } } } ] // replace root with key value https://stackoverflow.com/questions/66237048/how-to-replace-the-root-with-object-value-in-mongodb ====================================================================================================================================================================== ====================================================================================================================================================================== db.packages.update( {"catalogue.0":"58356a157f8b9a50613c5ec7",record_date:{"$gte": new Date('2019-02-14T00:00:00Z'),"$lte": new Date('2019-02-16T00:00:00Z')}}, { $set : { "streaming_mode" : "vodafone_android"}}, {multi: true}); db.SESSION.update({"catlogue.0":"58356a157f8b9a50613c5ec7"},{ $set : { "device_token" : ""}}, {multi: true}) db.SESSION.update({"catlogue.0":"58356a157f8b9a50613c5ec7"},{ $set : { "device_token" : ""}}, {multi: true}) db.SESSION.update({"catlogue.0":"58356a157f8b9a50613c5ec7"},{ $set : { "device_token" : ""}}, {multi: true}) db.SESSION.find({"catlogue.0":"58356a157f8b9a50613c5ec7" ,"device_token" : ""}) db.SESSION.find({"catlogue.0":"58356a157f8b9a50613c5ec7","device_token": {$exists: true, $not: {$size: 0}}}) db.SESSION.find({"catlogue.0":"58356a157f8b9a50613c5ec7","device_token": {$exists: true, $ne:''}}) {"streaming_mode" : "vodafone_android","asset_code" : "CH689","record_date" : ISODate("2019-06-15T18:30:00.000+0000")} db.packages.count( {"streaming_mode" : "vodafone_android","asset_code" : "CH689",record_date:{"$gte": new Date('2019-06-15T00:00:00Z'),"$lte": new Date('2019-06-15T23:59:00Z')}} ) db.packages.count( {"content_type":"LIVE","os_name" : "android","asset_code" : "CH689",record_date:{"$gte": new Date('2019-06-15T00:00:00Z'),"$lte": new Date('2019-06-15T23:59:00Z')}} ) db.packages.find( {"duration":{"$gte":30},"asset_code":{"$in":["CH370","CH369","CH368"]},"streaming_mode" : "vodafone_android","msisdn":/VFPlay/,record_date:{"$gte": new Date('2018-02-22T00:00:00Z'),"$lte": new Date('2019-02-23T00:00:00Z')}} ) db.packages.find( {"msisdn":/VFPlay/,record_date:{"$gte": new Date('2019-02-14T00:00:00Z'),"$lte": new Date('2018-07-16T00:00:00Z')}} ) db.packages.find( {"msisdn":/VFPlay/,"streaming_mode" => "vodafone_android",record_date:{"$gte": new Date('2019-02-23T00:00:00Z'),"$lte": new Date('2019-02-23T00:00:00Z')}} ) db.packages.find( {"msisdn":/VFPlay/,record_date:{"$gte": new Date('2019-02-14T00:00:00Z'),"$lte": new Date('2019-02-16T00:00:00Z')}} ) "msisdn":/VFPlay/,"streaming_mode" : "vodafone_android" {"msisdn":/VFPlay/,record_date:{"$gte": new Date('2019-02-14T00:00:00Z'),"$lte": new Date('2019-02-16T00:00:00Z')} db.packages.update( {"msisdn":/VFPlay/,record_date:{"$gte": new Date('2019-02-14T00:00:00Z'),"$lte": new Date('2019-02-16T00:00:00Z')}}, { $set : { "streaming_mode" : "vodafone_android"}}, {multi: true}); db.packages.find( {"duration":{"$gte":30},"asset_code":{"$in":["CH370","CH369","CH368"]},"streaming_mode" : "vodafone_android","msisdn":/VFPlay/,record_date:{"$gte": new Date('2018-06-05T00:00:00Z'),"$lte": new Date('2018-07-10T00:00:00Z')}} ) ====================================================================================================================================================================== db.ASSETS.update({"subject" : "epg"}, {$push: { "catlogue": "5ab0b35088abf255501c12f2" }},{multi:true}) db.UPLOADCRON.update({ "subject" : "epg" }, { $set: { "sync_status" : "pending" } }) ================================================================================================================================================================ db.packages.count({"streaming_mode" : "dailyhunt_digivive_offdeck",record_date:new Date('2018-07-03T00:00:00Z')}) db.packages.count({"streaming_mode" : "dailyhunt_digivive_offdeck",record_date:{"$gte": new Date('2018-07-03T00:00:00Z'),"$lte": new Date('2018-07-03T23:59:59Z')}}) db.free_paid_details.find({"app":"dailyhunt_digivive_offdeck",date:{"$gte": new Date('2018-07-04T00:00:00Z'),"$lte": new Date('2018-07-04T23:59:59Z')}}) db.packages.count({"streaming_mode" : "dailyhunt_digivive_offdeck",record_date:{"$gte": new Date('2018-07-03T00:00:00Z'),"$lte": new Date('2018-07-03T23:59:59Z')}}) db.packages.count({"streaming_mode" : "dailyhunt_digivive_offdeck",record_date:{"$gte": new Date('2018-07-03T00:00:00Z'),"$lte": new Date('2018-07-03T23:59:59Z')}}) db.free_paid_details.aggregate([{$match:{"app":"dailyhunt_digivive_offdeck",date:{"$gte": new Date('2018-06-18T00:00:00Z'),"$lte": new Date('2018-06-20T23:59:59Z')}}},{$group:{_id :total:{$sum:1},app:{$first:'$app'}}}]) db.free_paid_details.aggregate([{$match:{"app":"dailyhunt_digivive_offdeck",date:{"$gte": new Date('2018-06-01T00:00:00Z'),"$lte": new Date('2018-06-30T23:59:59Z')}}}]) db.nexgtv_app_hits_report.aggregate([{$match:{date:{"$gte": new Date('2018-06-18T00:00:00Z'),"$lte": new Date('2018-06-20T23:59:59Z')}}},{$group:{_id :{"date":"$date"}}}]) $group:{_id :{"tv_n":"$tv_n"} =============================================================================================================================================================== db.nexgtv_app_hits_report.aggregate([{$match:{date:{"$gte": new Date('2018-06-18T00:00:00Z'),"$lte": new Date('2018-06-20T23:59:59Z')}}},{$group:{_id :{"date":"$date"},totalcnt:{$sum:1},appname:{$first:'$appname'},totalcnt:{$first:'$totalcnt'},date:{$first:'$date'}}}]) //May -2021 db.packages.aggregate( [{$match:{"streaming_mode" : {'$ne':"vodafone_android"},asset_code:"CH903" ,"record_date":{'$gte': new Date('2020-12-01T00:00:00Z'), '$lte': new Date('2020-12-31T23:59:59Z')}}},{$group:{_id :{"asset_code": "$asset_code"},total_hits:{$sum:1}, ] ) db.packages.aggregate( [{$match:{"streaming_mode" : "dailyhunt_digivive_offdeck",asset_code:{$ne:'',$ne:null},record_date:{"$gte": new Date('2018-03-01T00:00:00Z'), "$lte": new Date('2018-03-04T23:59:59Z')}}},{$group:{_id :{"record_date": "$record_date" ,"asset_code":"$asset_code","paid_status":"$paid_status"},total_hits:{$sum:1},'duration':{'$sum':'$duration'}, duration:{$sum:'$duration'},record_date:{$first:'$record_date'}, 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:{'duration':-1}}] ) db.packages.aggregate( [{$match:{"streaming_mode" : {'$ne':"vodafone_android"},"duration":{"$gte":57},asset_code:"CH903" ,"record_date":{'$gte': new Date('2020-12-01T00:00:00Z'), '$lte': new Date('2020-12-31T23:59:59Z')}}},{$group:{_id :{"asset_code": "$asset_code","msisdn": "$msisdn"},total_hits:{$sum:1},"total_duration":{"$sum":"$duration"} ] ) "catalogue_name":"platform8" db.packages.aggregate( [{$match:{"catalogue_name" : "platform8",asset_code:"PFMOVASG01" ,"record_date":{'$gte': new Date('2021-09-06T00:00:00Z'), '$lte': new Date('2021-09-07T23:59:59Z')}}},{$group:{_id :{"asset_code": "$asset_code"},total_hits:{$sum:1},"total_duration":{"$sum":"$duration"} ] ) db.packages.aggregate([{"$match":{"record_date":{"$gte":{"$date":{"$numberLong":"1630953000000"}},"$lte":{"$date":{"$numberLong":"1631039399999"}}},"streaming_mode":{"$regex":"^platform8","$options":"i"}}},{"$group":{"_id":null,"totalHits":{"$sum":1},"total_duration":{"$sum":"$duration"}}},{"$project":{"_id":0,"totalHits":1,"total_duration":1}}]) db.packages.aggregate( [{$match:{"streaming_mode" : {'$ne':"vodafone_android"},"duration":{"$gte":57},asset_code:"CH903" ,"record_date":{'$gte': new Date('2020-12-01T00:00:00Z'), '$lte': new Date('2020-12-31T23:59:59Z')}}},{$group:{_id :{"asset_code": "$asset_code"},total_hits:{$sum:1}}} ] ) db.packages.aggregate( [{$match:{"streaming_mode" : {'$ne':"vodafone_android"},"duration":{"$gte":57},asset_code:"CH903" ,"record_date":{'$gte': new Date('2020-12-01T00:00:00Z'), '$lte': new Date('2020-12-31T23:59:59Z')}}},{$group:{_id :{"msisdn": "$msisdn"},total_hits:{$sum:1}}}, {$group:{_id :{"msisdn": "$_id.msisdn"},totalCount:{$sum:"$total_hits"},"distinctCount": { "$sum": 1 }}} ] ) db.packages.aggregate( [{$match:{"streaming_mode" : {'$ne':"vodafone_android"},"duration":{"$gte":57},asset_code:"CH902" ,"record_date":{'$gte': new Date('2020-12-01T00:00:00Z'), '$lte': new Date('2020-12-31T23:59:59Z')}}},{$group:{_id :{"msisdn": "$msisdn"},total_hits:{$sum:1}}}, {$group:{_id :{"msisdn": "$_id.msisdn"},totalCount:{$sum:"$total_hits"},"distinctCount": { "$sum": 1 }}} ] ) db.packages.aggregate( [{$match:{asset_code:{$ne:'',$ne:null},record_date:{"$gte": new Date('2018-03-01T00:00:00Z'), "$lte": new Date('2018-03-31T23:59:59Z')}}},{$group:{_id :{"record_date": "$record_date" ,"asset_code":"$asset_code","paid_status":"$paid_status"},total_hits:{$sum:1},'duration':{'$sum':'$duration'}, duration:{$sum:'$duration'},record_date:{$first:'$record_date'}, 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:{'duration':-1}}] ) db.KEYWORDS.aggregate( {$group : { '_id' : "$title",'status':{'$first':'$status'},'id':{'$first':'$_id'},"uniqueIds":{"$addToSet":"$_id"} }}, { $project : { title : 1,status:1,uniqueIds:1 } } ) db.KEYWORDS.aggregate( [ { $group : { _id : "$title", data: { $push: "$$ROOT" } } } ] ) db.ASSETS.update( { _id: 56e156139da23c60750e692d }, { $addToSet: { catlogue: "5d52a59dc8d1450aa73a8595" } } ) =========================================================================================================================================================== //Filter Records db.KEYWORDS.aggregate( [ { $match: { $text: { $search: "operating" } } }, { $sort: { score: { $meta: "textScore" }, posts: -1 } } ] ) ===================================================================================================================================================================== //Month Wise channel hits db.packages.aggregate( [{$match:{"content_type":"LIVE",streaming_mode:{$ne:'vodafone_android'},asset_code:{$ne:'',$ne:null},record_date:{"$gte": new Date('2021-08-01T00:00:00Z'), "$lte": new Date('2021-08-31T23:59:59Z')}}},{$group:{_id :{"asset_code":"$asset_code","paid_status":"$paid_status"},total_hits:{$sum:1},'duration':{'$sum':'$duration'}, 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:{'duration':-1}}] ) ======================================================================================================================================================== $conver with on error /** * replacementDocument: A document or string. */ { "newRoot": { "$arrayToObject": [ [ { k: "$title", v: { '$arrayToObject': { '$concatArrays': [ [ { 'k': 'is_recurring', 'v': '$is_recurring' }, { 'k': '$title', 'v': { '$arrayToObject': { '$concatArrays': [ '$final_data' ] } } } ] ] } } } ] ] } } ============================================================================================================= [ { '$match': { 'parent_id': 0 } }, { '$sort': { '_id': 1 } }, { '$addFields': { 'parent_id': { '$toString': '$_id' } } }, { '$lookup': { 'from': 'PAYMENTMODES', 'localField': 'parent_id', 'foreignField': 'parent_id', 'as': 'data' } }, { '$addFields': { 'final_data': { '$map': { 'input': '$data', 'as': 'g', 'in': { 'k': '$$g.title', 'v': { 'is_recurring': '$$g.is_recurring', 'image': '$$g.image' } } } } } }, { '$replaceRoot': { 'newRoot': { '$arrayToObject': { '$concatArrays': [ [ { 'k': 'is_recurring', 'v': '$is_recurring' }, { 'k': 'image', 'v': { '$convert': { 'input': '$image', 'to': 'string', 'onNull': '', 'onError': '' } } }, { 'k': 'mode', 'v': '$title' }, { 'k': '$title', 'v': { '$arrayToObject': { '$concatArrays': [ '$final_data' ] } } } ] ] } } } } ] ============================================================================================================================================================ Key value root replace [ { '$match': { 'parent_id': 0 } }, { '$sort': { '_id': 1 } }, { '$addFields': { 'parent_id': { '$toString': '$_id' } } }, { '$lookup': { 'from': 'PAYMENTMODES', 'localField': 'parent_id', 'foreignField': 'parent_id', 'as': 'data' } }, { '$addFields': { 'final_data': { '$map': { 'input': '$data', 'as': 'g', 'in': { 'is_recurring': '$$g.is_recurring', 'image': '$$g.image', 'title': '$$g.title' } } } } }, { '$replaceRoot': { 'newRoot': { '$arrayToObject': { '$concatArrays': [ [ { 'k': 'is_recurring', 'v': '$is_recurring' }, { 'k': 'image', 'v': { '$convert': { 'input': '$image', 'to': 'string', 'onNull': '', 'onError': '' } } }, { 'k': 'mode', 'v': '$title' }, { 'k': '$title', 'v': '$final_data' } ] ] } } } } ] ========================================================================================================================================================== Filter with lookup [ { '$match': { 'type': 'movie' } }, { '$lookup': { 'from': 'BITFRAME', 'let': { 'code': '$code' }, 'pipeline': [ { '$match': { '$expr': { '$and': [ { '$eq': [ '$code', '$$code' ] } ] } } }, { '$sort': { 'bit_frame': 1 } } ], 'as': 'bitframeurl' } }, { '$addFields': { 'sd_download': { '$filter': { 'input': '$bitframeurl', 'as': 'num', 'cond': { '$and': [ { '$eq': [ '$$num.content_download', '1' ] }, { '$in': [ '$$num.bit_frame', [ '360', '320' ] ] } ] } } }, 'hd_download': { '$filter': { 'input': '$bitframeurl', 'as': 'num', 'cond': { '$and': [ { '$eq': [ '$$num.content_download', '1' ] }, { '$eq': [ '$$num.bit_frame', '720' ] } ] } } }, 'content': { '$filter': { 'input': '$bitframeurl', 'as': 'num', 'cond': { '$and': [ { '$eq': [ '$$num.content_download', '0' ] } ] } } } } }, { '$addFields': { 'content_obj': { '$first': '$content' }, 'sd_obj': { '$first': '$sd_download' }, 'hd_obj': { '$first': '$hd_download' } } }, { '$project': { '_id': 1, 'code': 1, 'premium_hls': '$content_obj.url', 'hd_url': '$hd_obj.url', 'sd_url': '$sd_obj.url', 'hd_bitframe': '$hd_obj.bit_frame', 'sd_bitframe': '$sd_obj.bit_frame', 'hd_size': 1, 'sd_size': 1 } } ] ==================================================================================================================================================== Update with foreach ["VOD81600"].forEach(function(result) { db.ASSETS.update({"code" : result}, {$set : {"viewerrating_id" : "6053008864dee72bd4e52ebe","content_advisory" : [ "605993c9e1e5ed93d4d36af9" ]}}); }) ==================================================================================================================================================== //BitFrame URL query [ { '$match': { 'type': 'movie', 'code': 'MOV4022' } }, { '$lookup': { 'from': 'BITFRAME', 'let': { 'code': '$code' }, 'pipeline': [ { '$match': { '$expr': { '$and': [ { '$eq': [ '$code', '$$code' ] } ] } } }, { '$sort': { 'bit_frame': 1 } } ], 'as': 'bitframeurl' } }, { '$addFields': { 'sd_download': { '$filter': { 'input': '$bitframeurl', 'as': 'num', 'cond': { '$and': [ { '$eq': [ '$$num.content_download', '1' ] }, { '$in': [ '$$num.bit_frame', [ '360', '320' ] ] } ] } } }, 'hd_download': { '$filter': { 'input': '$bitframeurl', 'as': 'num', 'cond': { '$and': [ { '$eq': [ '$$num.content_download', '1' ] }, { '$eq': [ '$$num.bit_frame', '720' ] } ] } } }, 'content': { '$filter': { 'input': '$bitframeurl', 'as': 'num', 'cond': { '$and': [ { '$eq': [ '$$num.content_download', '0' ] } ] } } } } }, { '$addFields': { 'content_obj': { '$first': '$content' }, 'sd_obj': { '$first': '$sd_download' }, 'hd_obj': { '$first': '$hd_download' } } }, { '$addFields': { 'bitframeurl_play': { 'premiumn_hls': { '$convert': { 'input': { '$first': '$content.url' }, 'to': 'string', 'onNull': '', 'onError': '' } }, 'standred_hls': '' }, 'hd': { 'url': { '$convert': { 'input': { '$first': '$hd_download.url' }, 'to': 'string', 'onNull': '', 'onError': '' } }, 'bitframe': { '$convert': { 'input': { '$first': '$hd_download.bit_frame' }, 'to': 'string', 'onNull': '', 'onError': '' } }, 'size': { '$convert': { 'input': '$hd_size', 'to': 'int', 'onNull': 0, 'onError': 0 } } }, 'sd': { 'url': { '$convert': { 'input': { '$first': '$sd_download.url' }, 'to': 'string', 'onNull': '', 'onError': '' } }, 'bitframe': { '$convert': { 'input': { '$first': '$sd_download.bit_frame' }, 'to': 'string', 'onNull': '', 'onError': '' } }, 'size': { '$convert': { 'input': '$sd_size', 'to': 'int', 'onNull': 0, 'onError': 0 } } } } }, { '$project': { '_id': 0, 'bitframeurl_play': 1, 'hd': 1, 'sd': 1, 'code': 1 } } ] ==================================================================================================================================================