Issue creating a polyline dynamically - react-leaflet

I have an issue where I'm creating a dynamic polyline based on various user trips. I create an array of latlong positions based off the user for a given trip, however, when I set the positions for the PolyLine it appears to draw multiple lines. I can create a const global array with the same coordinates and use it and it all works fine. For example, if I set linePositions=myRouteTest it loads the line fine. Any thoughts.
Here is the code:
import React, { useState, useCallback, useEffect, useRef } from 'react'
import L from 'leaflet';
import { LayersControl, Polyline} from 'react-leaflet'
import Alert from 'react-s-alert';
import { floor, random } from 'mathjs'
const myRouteTest = [
[34.452013,-75.821677],
[34.457749,-75.823401],
[34.462844,-75.827613],
[34.467903,-75.831405],
[34.469101,-75.825433],
[34.472537,-75.826517],
[34.46738,-75.823303],
[34.466348,-75.821663],
[34.462159,-75.815665],
[34.457858,-75.809724],
[34.453227,-75.806552],
[34.450229,-75.803527],
[34.444998,-75.798925],
[34.439271,-75.796441],
[34.433141,-75.796452],
[34.482771,-75.718814],
[34.51903,-76.442413],
[34.519628,-76.465259],
[34.521005,-76.48865],
[34.525232,-76.508717]
]
export default function TripLine2({trip}) {
return (
<div>
<LayersControl.Overlay checked name={trip.name}>
<CFTripLine trip={trip} />
</LayersControl.Overlay>
</div>
)
}
const CFTripLine = ({ trip }) => {
const [linePositions, setLinePositions] = useState([]);
const [color, setColor] = useState();
useEffect(() => {
var tempLatLong = [];
trip.tripWaypoint.map(waypoint =>
tempLatLong.push([Number(waypoint.latitude), Number(waypoint.longitude)])
);
setLinePositions(tempLatLong);
console.log("New: " + tempLatLong);
console.log("const: " + myRouteTest);
//dynamically set the line color for the trip
setColor({ color: getColor() });
}, []);
const getColor = () => {
console.log("getting color");
var r = floor(random() * 255);
var g = floor(random() * 255);
var b = floor(random() * 255)
return "rgb(" + r + " ," + g + "," + b + ")";
}
return (
<div>
{
(linePositions && linePositions.length > 0) ? <Polyline pathOptions={color} positions={linePositions} /> : null
}
</div>
)
}
Here is an example json:
{
"tripID":1,
"user":{
"id":2,
"name":"test,
"profile":null,
"waypoints":[
],
"email":"test",
"imageUrl":null,
"emailVerified":true,
"provider":null,
"providerId":null
},
"tripWaypoint":[
{
"id":1,
"latitude":34.67599502764642,
"longitude":-76.65639395825565,
"speed":0.0,
"elevation":0.0,
"name":"TW0.4625323333214715"
},
{
"id":2,
"latitude":34.66065698303282,
"longitude":-76.64228503592312,
"speed":0.0,
"elevation":0.0,
"name":"TW0.0658351705169683"
},
{
"id":3,
"latitude":34.64539797976613,
"longitude":-76.62809598259628,
"speed":0.0,
"elevation":0.0,
"name":"TW0.957917922018214"
},
{
"id":4,
"latitude":34.63000402785838,
"longitude":-76.61363703198731,
"speed":0.0,
"elevation":0.0,
"name":"TW0.8996815085608042"
},
{
"id":5,
"latitude":34.61495096795261,
"longitude":-76.59945501945913,
"speed":0.0,
"elevation":0.0,
"name":"TW0.025047788294637496"
},
{
"id":6,
"latitude":34.60001399740577,
"longitude":-76.58547802828252,
"speed":0.0,
"elevation":0.0,
"name":"TW0.37358115819515314"
},
{
"id":7,
"latitude":34.58539696410298,
"longitude":-76.5720789693296,
"speed":0.0,
"elevation":0.0,
"name":"TW0.05164300416673007"
},
{
"id":8,
"latitude":34.5717020239681,
"longitude":-76.55940997414291,
"speed":0.0,
"elevation":0.0,
"name":"TW0.3285483477149437"
},
{
"id":9,
"latitude":34.55762797035277,
"longitude":-76.54618903063238,
"speed":0.0,
"elevation":0.0,
"name":"TW0.3439910413133228"
},
{
"id":10,
"latitude":34.54380503855646,
"longitude":-76.53298996388912,
"speed":0.0,
"elevation":0.0,
"name":"TW0.7025978234833568"
},
{
"id":11,
"latitude":34.52656396664679,
"longitude":-76.51689796708524,
"speed":0.0,
"elevation":0.0,
"name":"TW0.9951697714467905"
},
{
"id":12,
"latitude":34.52151001431048,
"longitude":-76.49242197163403,
"speed":0.0,
"elevation":0.0,
"name":"TW0.1347634133562452"
},
{
"id":13,
"latitude":34.52400497160852,
"longitude":-76.46309201605618,
"speed":0.0,
"elevation":0.0,
"name":"TW0.24147729087646597"
},
{
"id":14,
"latitude":34.52595896087587,
"longitude":-76.43877200782299,
"speed":0.0,
"elevation":0.0,
"name":"TW0.7316560643332694"
},
{
"id":15,
"latitude":34.5288119930774,
"longitude":-76.41897697001696,
"speed":0.0,
"elevation":0.0,
"name":"TW0.8294183964830047"
},
{
"id":16,
"latitude":34.53094895929098,
"longitude":-76.39967202208936,
"speed":0.0,
"elevation":0.0,
"name":"TW0.5607757280076388"
},
{
"id":17,
"latitude":34.53380299732089,
"longitude":-76.37227996252477,
"speed":0.0,
"elevation":0.0,
"name":"TW0.5260754134537965"
},
{
"id":18,
"latitude":34.53482600860298,
"longitude":-76.35333904065192,
"speed":0.0,
"elevation":0.0,
"name":"TW0.3571899945440181"
},
{
"id":19,
"latitude":34.53746899031103,
"longitude":-76.3336119800806,
"speed":0.0,
"elevation":0.0,
"name":"TW0.09533153270937111"
},
{
"id":20,
"latitude":34.53914604149759,
"longitude":-76.31359599530697,
"speed":0.0,
"elevation":0.0,
"name":"TW0.3209122099401692"
},
{
"id":21,
"latitude":34.54269703477621,
"longitude":-76.29412399604917,
"speed":0.0,
"elevation":0.0,
"name":"TW0.33219391704748347"
},
{
"id":22,
"latitude":34.54546197317541,
"longitude":-76.27408797852695,
"speed":0.0,
"elevation":0.0,
"name":"TW0.8438944089925343"
},
{
"id":23,
"latitude":34.54856897704303,
"longitude":-76.25491102226079,
"speed":0.0,
"elevation":0.0,
"name":"TW0.36398386573914765"
},
{
"id":24,
"latitude":34.550529001280665,
"longitude":-76.23528001829982,
"speed":0.0,
"elevation":0.0,
"name":"TW0.03115800604559138"
},
{
"id":25,
"latitude":34.55335898324847,
"longitude":-76.21489296667278,
"speed":0.0,
"elevation":0.0,
"name":"TW0.6726480940845876"
},
{
"id":26,
"latitude":34.55648803152144,
"longitude":-76.19424004107714,
"speed":0.0,
"elevation":0.0,
"name":"TW0.10400848032177046"
},
{
"id":27,
"latitude":34.55834697000682,
"longitude":-76.17363799363375,
"speed":0.0,
"elevation":0.0,
"name":"TW0.714751966626381"
},
{
"id":28,
"latitude":34.56060002557933,
"longitude":-76.1526610236615,
"speed":0.0,
"elevation":0.0,
"name":"TW0.2189323091239299"
},
{
"id":29,
"latitude":34.56355799920857,
"longitude":-76.13186501897871,
"speed":0.0,
"elevation":0.0,
"name":"TW0.6783163111638825"
},
{
"id":30,
"latitude":34.56705903634429,
"longitude":-76.11068302765489,
"speed":0.0,
"elevation":0.0,
"name":"TW0.06869450828961199"
},
{
"id":31,
"latitude":34.56918896175921,
"longitude":-76.08934697695076,
"speed":0.0,
"elevation":0.0,
"name":"TW0.6476584186153899"
},
{
"id":32,
"latitude":34.571133982390165,
"longitude":-76.06715697795153,
"speed":0.0,
"elevation":0.0,
"name":"TW0.40800681731430233"
},
{
"id":33,
"latitude":34.573455015197396,
"longitude":-76.04622200131416,
"speed":0.0,
"elevation":0.0,
"name":"TW0.09351924762239894"
},
{
"id":34,
"latitude":34.576887991279364,
"longitude":-76.02514503523707,
"speed":0.0,
"elevation":0.0,
"name":"TW0.5612109189517532"
},
{
"id":35,
"latitude":34.57823798060417,
"longitude":-76.00225003436208,
"speed":0.0,
"elevation":0.0,
"name":"TW0.2763567018455305"
},
{
"id":36,
"latitude":34.581467024981976,
"longitude":-75.98089001141489,
"speed":0.0,
"elevation":0.0,
"name":"TW0.11062887879355576"
},
{
"id":37,
"latitude":34.5608470402658,
"longitude":-75.72843203321099,
"speed":0.0,
"elevation":0.0,
"name":"TW0.47173268062798046"
},
{
"id":38,
"latitude":34.56802597269416,
"longitude":-75.7275060005486,
"speed":0.0,
"elevation":0.0,
"name":"TW0.5591163063586786"
},
{
"id":39,
"latitude":34.5688250195235,
"longitude":-75.7319599762559,
"speed":0.0,
"elevation":0.0,
"name":"TW0.2898243232100508"
},
{
"id":40,
"latitude":34.565973998978734,
"longitude":-75.73355304077268,
"speed":0.0,
"elevation":0.0,
"name":"TW0.4270751759829343"
},
{
"id":41,
"latitude":34.56311400979757,
"longitude":-75.73644001968205,
"speed":0.0,
"elevation":0.0,
"name":"TW0.17347115786989065"
},
{
"id":42,
"latitude":34.55965102650225,
"longitude":-75.73762899264693,
"speed":0.0,
"elevation":0.0,
"name":"TW0.24153172732682693"
},
{
"id":43,
"latitude":34.55576098524034,
"longitude":-75.73758297599852,
"speed":0.0,
"elevation":0.0,
"name":"TW0.09368325732232441"
},
{
"id":44,
"latitude":34.55504802055657,
"longitude":-75.73932901024818,
"speed":0.0,
"elevation":0.0,
"name":"TW0.352275568518189"
},
{
"id":45,
"latitude":34.551925007253885,
"longitude":-75.73927603662014,
"speed":0.0,
"elevation":0.0,
"name":"TW0.7066560187648049"
},
{
"id":46,
"latitude":34.55122201703489,
"longitude":-75.73800198733807,
"speed":0.0,
"elevation":0.0,
"name":"TW0.7575265591964035"
},
{
"id":47,
"latitude":34.55780197866261,
"longitude":-75.73855795897543,
"speed":0.0,
"elevation":0.0,
"name":"TW0.7461685765935566"
},
{
"id":48,
"latitude":34.55529101192951,
"longitude":-75.74234196916223,
"speed":0.0,
"elevation":0.0,
"name":"TW0.8198115507403634"
},
{
"id":49,
"latitude":34.552761018276215,
"longitude":-75.74417802505195,
"speed":0.0,
"elevation":0.0,
"name":"TW0.16950813703065937"
},
{
"id":50,
"latitude":34.54882697202265,
"longitude":-75.74381399899721,
"speed":0.0,
"elevation":0.0,
"name":"TW0.22298291541737503"
},
{
"id":51,
"latitude":34.544748002663255,
"longitude":-75.74202303774655,
"speed":0.0,
"elevation":0.0,
"name":"TW0.7891177318371495"
},
{
"id":52,
"latitude":34.540386982262135,
"longitude":-75.73906799778342,
"speed":0.0,
"elevation":0.0,
"name":"TW0.975506647616044"
},
{
"id":53,
"latitude":34.536646977066994,
"longitude":-75.73515800759196,
"speed":0.0,
"elevation":0.0,
"name":"TW0.5569825078315026"
},
{
"id":54,
"latitude":34.53338800929487,
"longitude":-75.73283999226987,
"speed":0.0,
"elevation":0.0,
"name":"TW0.05583224680540411"
},
{
"id":55,
"latitude":34.67599502764642,
"longitude":-76.65639395825565,
"speed":0.0,
"elevation":0.0,
"name":"TW0.8409539568596216"
},
{
"id":56,
"latitude":34.66065698303282,
"longitude":-76.64228503592312,
"speed":0.0,
"elevation":0.0,
"name":"TW0.16599150275016417"
},
{
"id":57,
"latitude":34.64539797976613,
"longitude":-76.62809598259628,
"speed":0.0,
"elevation":0.0,
"name":"TW0.4739875420965156"
},
{
"id":58,
"latitude":34.63000402785838,
"longitude":-76.61363703198731,
"speed":0.0,
"elevation":0.0,
"name":"TW0.39334685729929575"
},
{
"id":59,
"latitude":34.61495096795261,
"longitude":-76.59945501945913,
"speed":0.0,
"elevation":0.0,
"name":"TW0.8664896036237502"
},
{
"id":60,
"latitude":34.60001399740577,
"longitude":-76.58547802828252,
"speed":0.0,
"elevation":0.0,
"name":"TW0.6520395010294587"
},
{
"id":61,
"latitude":34.58539696410298,
"longitude":-76.5720789693296,
"speed":0.0,
"elevation":0.0,
"name":"TW0.3621095349898389"
},
{
"id":62,
"latitude":34.5717020239681,
"longitude":-76.55940997414291,
"speed":0.0,
"elevation":0.0,
"name":"TW2.087810425505099E-4"
},
{
"id":63,
"latitude":34.55762797035277,
"longitude":-76.54618903063238,
"speed":0.0,
"elevation":0.0,
"name":"TW0.36747627597440136"
},
{
"id":64,
"latitude":34.54380503855646,
"longitude":-76.53298996388912,
"speed":0.0,
"elevation":0.0,
"name":"TW0.11213289899397283"
},
{
"id":65,
"latitude":34.52656396664679,
"longitude":-76.51689796708524,
"speed":0.0,
"elevation":0.0,
"name":"TW0.6912885791691252"
},
{
"id":66,
"latitude":34.52151001431048,
"longitude":-76.49242197163403,
"speed":0.0,
"elevation":0.0,
"name":"TW0.7723663588134086"
},
{
"id":67,
"latitude":34.52400497160852,
"longitude":-76.46309201605618,
"speed":0.0,
"elevation":0.0,
"name":"TW0.34818032694997414"
},
{
"id":68,
"latitude":34.52595896087587,
"longitude":-76.43877200782299,
"speed":0.0,
"elevation":0.0,
"name":"TW0.5886342804520899"
},
{
"id":69,
"latitude":34.5288119930774,
"longitude":-76.41897697001696,
"speed":0.0,
"elevation":0.0,
"name":"TW0.6938691766520492"
},
{
"id":70,
"latitude":34.53094895929098,
"longitude":-76.39967202208936,
"speed":0.0,
"elevation":0.0,
"name":"TW0.6692289842573389"
},
{
"id":71,
"latitude":34.53380299732089,
"longitude":-76.37227996252477,
"speed":0.0,
"elevation":0.0,
"name":"TW0.8018638276009495"
},
{
"id":72,
"latitude":34.53482600860298,
"longitude":-76.35333904065192,
"speed":0.0,
"elevation":0.0,
"name":"TW0.6471011203293123"
},
{
"id":73,
"latitude":34.53746899031103,
"longitude":-76.3336119800806,
"speed":0.0,
"elevation":0.0,
"name":"TW0.12567493925344364"
},
{
"id":74,
"latitude":34.53914604149759,
"longitude":-76.31359599530697,
"speed":0.0,
"elevation":0.0,
"name":"TW0.6655390642371621"
},
{
"id":75,
"latitude":34.54269703477621,
"longitude":-76.29412399604917,
"speed":0.0,
"elevation":0.0,
"name":"TW0.6369027275191426"
},
{
"id":76,
"latitude":34.54546197317541,
"longitude":-76.27408797852695,
"speed":0.0,
"elevation":0.0,
"name":"TW0.16869626017905148"
},
{
"id":77,
"latitude":34.54856897704303,
"longitude":-76.25491102226079,
"speed":0.0,
"elevation":0.0,
"name":"TW0.22723393420759863"
},
{
"id":78,
"latitude":34.550529001280665,
"longitude":-76.23528001829982,
"speed":0.0,
"elevation":0.0,
"name":"TW0.10429919005986765"
},
{
"id":79,
"latitude":34.55335898324847,
"longitude":-76.21489296667278,
"speed":0.0,
"elevation":0.0,
"name":"TW0.4153754450341114"
},
{
"id":80,
"latitude":34.55648803152144,
"longitude":-76.19424004107714,
"speed":0.0,
"elevation":0.0,
"name":"TW0.3763104488946786"
},
{
"id":81,
"latitude":34.55834697000682,
"longitude":-76.17363799363375,
"speed":0.0,
"elevation":0.0,
"name":"TW0.5280073574891413"
},
{
"id":82,
"latitude":34.56060002557933,
"longitude":-76.1526610236615,
"speed":0.0,
"elevation":0.0,
"name":"TW0.6534220112784409"
},
{
"id":83,
"latitude":34.56355799920857,
"longitude":-76.13186501897871,
"speed":0.0,
"elevation":0.0,
"name":"TW0.012306756873057156"
},
{
"id":84,
"latitude":34.56705903634429,
"longitude":-76.11068302765489,
"speed":0.0,
"elevation":0.0,
"name":"TW0.4069277174747923"
},
{
"id":85,
"latitude":34.56918896175921,
"longitude":-76.08934697695076,
"speed":0.0,
"elevation":0.0,
"name":"TW0.38745049458472636"
},
{
"id":86,
"latitude":34.571133982390165,
"longitude":-76.06715697795153,
"speed":0.0,
"elevation":0.0,
"name":"TW0.9213088212832486"
},
{
"id":87,
"latitude":34.573455015197396,
"longitude":-76.04622200131416,
"speed":0.0,
"elevation":0.0,
"name":"TW0.320353230478409"
},
{
"id":88,
"latitude":34.576887991279364,
"longitude":-76.02514503523707,
"speed":0.0,
"elevation":0.0,
"name":"TW0.9859279126269395"
},
{
"id":89,
"latitude":34.57823798060417,
"longitude":-76.00225003436208,
"speed":0.0,
"elevation":0.0,
"name":"TW0.1989627279533166"
},
{
"id":90,
"latitude":34.581467024981976,
"longitude":-75.98089001141489,
"speed":0.0,
"elevation":0.0,
"name":"TW0.6703525795602392"
},
{
"id":91,
"latitude":34.5608470402658,
"longitude":-75.72843203321099,
"speed":0.0,
"elevation":0.0,
"name":"TW0.42256831709235443"
},
{
"id":92,
"latitude":34.56802597269416,
"longitude":-75.7275060005486,
"speed":0.0,
"elevation":0.0,
"name":"TW0.5334353414149261"
},
{
"id":93,
"latitude":34.5688250195235,
"longitude":-75.7319599762559,
"speed":0.0,
"elevation":0.0,
"name":"TW0.9962580080816836"
},
{
"id":94,
"latitude":34.565973998978734,
"longitude":-75.73355304077268,
"speed":0.0,
"elevation":0.0,
"name":"TW0.48239944630269926"
},
{
"id":95,
"latitude":34.56311400979757,
"longitude":-75.73644001968205,
"speed":0.0,
"elevation":0.0,
"name":"TW0.23498643785927986"
},
{
"id":96,
"latitude":34.55965102650225,
"longitude":-75.73762899264693,
"speed":0.0,
"elevation":0.0,
"name":"TW0.33848582367790947"
},
{
"id":97,
"latitude":34.55576098524034,
"longitude":-75.73758297599852,
"speed":0.0,
"elevation":0.0,
"name":"TW0.796415769143147"
},
{
"id":98,
"latitude":34.55504802055657,
"longitude":-75.73932901024818,
"speed":0.0,
"elevation":0.0,
"name":"TW0.6764924242169598"
},
{
"id":99,
"latitude":34.551925007253885,
"longitude":-75.73927603662014,
"speed":0.0,
"elevation":0.0,
"name":"TW0.48111721516412054"
},
{
"id":100,
"latitude":34.55122201703489,
"longitude":-75.73800198733807,
"speed":0.0,
"elevation":0.0,
"name":"TW0.27369946100558806"
},
{
"id":101,
"latitude":34.55780197866261,
"longitude":-75.73855795897543,
"speed":0.0,
"elevation":0.0,
"name":"TW0.38984718591276835"
},
{
"id":102,
"latitude":34.55529101192951,
"longitude":-75.74234196916223,
"speed":0.0,
"elevation":0.0,
"name":"TW0.2567598848429836"
},
{
"id":103,
"latitude":34.552761018276215,
"longitude":-75.74417802505195,
"speed":0.0,
"elevation":0.0,
"name":"TW0.0020425480484795866"
},
{
"id":104,
"latitude":34.54882697202265,
"longitude":-75.74381399899721,
"speed":0.0,
"elevation":0.0,
"name":"TW0.8913092512422502"
},
{
"id":105,
"latitude":34.544748002663255,
"longitude":-75.74202303774655,
"speed":0.0,
"elevation":0.0,
"name":"TW0.44463940288519654"
},
{
"id":106,
"latitude":34.540386982262135,
"longitude":-75.73906799778342,
"speed":0.0,
"elevation":0.0,
"name":"TW0.6771001703845265"
},
{
"id":107,
"latitude":34.536646977066994,
"longitude":-75.73515800759196,
"speed":0.0,
"elevation":0.0,
"name":"TW0.8286605038270607"
},
{
"id":108,
"latitude":34.53338800929487,
"longitude":-75.73283999226987,
"speed":0.0,
"elevation":0.0,
"name":"TW0.6408112678998857"
}
],
"startTime":"2022-03-01T12:22:46.731+00:00",
"endTime":"2022-03-01T12:22:46.731+00:00",
"name":"tripTest1"
}

Related

3rd level nesting lookup rewind at level3 in mongodb

I have to add permissions data at each level by getting data(permission object) by permision_id from the permissions collection
at lease one level will contain permission_id and at most 3 levels can have permission_id
Sample Data looks like
{
"name": "label 1",
"permision_id": "1",
"level2": [
{
"name": "label 2.1",
"permision_id": "2",
"level3": [
{
"name": "lebel 3.1",
"permision_id": "8"
},
{
"name": "lebel 3.2",
"permision_id": "6"
}
]
},
{
"name": "label 2.2",
"permision_id": "5"
}
]
}
what I have tried
[
{
'$lookup': {
'from': 'permissions',
'localField': 'permission_id',
'foreignField': '_id',
'as': 'permissions'
}
}, {
'$unwind': {
'path': '$permissions',
'preserveNullAndEmptyArrays': true
}
}, {
'$unwind': {
'path': '$level2',
'preserveNullAndEmptyArrays': true
}
}, {
'$lookup': {
'from': 'permissions',
'let': {
'level2_permission_id': '$level2.permissions_id'
},
'pipeline': [
{
'$match': {
'$expr': {
'$eq': [
'$_id', '$$level2_permission_id'
]
}
}
}
],
'as': 'level2.permissions'
}
}, {
'$unwind': {
'path': '$level2.permissions',
'preserveNullAndEmptyArrays': true
}
}, {
'$unwind': {
'path': '$level2.level3',
'preserveNullAndEmptyArrays': true
}
}, {
'$lookup': {
'from': 'permissions',
'let': {
'level3_permission_id': '$level2.level3.permission_id'
},
'pipeline': [
{
'$match': {
'$expr': {
'$eq': [
'$_id', '$$level3_permission_id'
]
}
}
}
],
'as': 'level2.level3.permissions'
}
}, {
'$unwind': {
'path': '$level2.level3.permissions',
'preserveNullAndEmptyArrays': true
}
},{
'$group': {
'_id': '$_id',
'level2': {
'$push': '$level2'
}
}
}
]
Now the problem is level2 data is pushedd as an array at level1 correctly but I am unable to push level3 data to level2.
Output i got
{
"name": "label 1",
"permision_id": "1",
"permissions": {
"access": true,
"otherPermission": {...}
}
"level2": [
{
"name": "label 2.1",
"permision_id": "2",
"permissions": {
"access": true,
"otherPermission": {...}
}
"level3": {
"permision_id": "8"
"permissions": {
"access": true,
"otherPermission": {...}
}
}
},
{
"name": "label 2.2",
"permision_id": "5"
"permissions": {
"access": true,
"otherPermission": {...}
}
}
]
}
Output Expected at level 2 (level will reamins same)
at level 3 should be array of items with
"level2": [
{
"name": "label 2.1",
"permision_id": "2",
"permissions": {
"access": true,
"otherPermission": {...}
}
"level3": [
{
"name": "lebel 3.1",
"permision_id": "8"
"permissions": {
"access": true,
"otherPermission": {...}
}
},
{
"name": "lebel 3.2",
"permision_id": "6"
"permissions": {
"access": true,
"otherPermission": {...}
}
}
]
},
{
"name": "label 2.2",
"permision_id": "5"
"permissions": {
"access": true,
"otherPermission": {...}
}
}
]

RESTful architecture file to openAPI file

I'm new working with APIs and its documentation. However, I need to get an openAPI or swagger file from a RESTful API.
I have tried a couple of libraries (goswagger.io, rest.sh) and swaggerHub or Apimatic.io. However, I have not find a way to transform the file I have to a proper swagger structure.
Is it possible to get from the definition file I have for the RESTful API to an openAPI swagger?
Here is a snippet of the file I need to transform:
{
"models":{
"com.linkedin.analytics.GetTimeseriesAggregatedStatsResponse":{
"namespace":"com.linkedin.analytics",
"name":"GetTimeseriesAggregatedStatsResponse",
"fields":[
{
"type":"string",
"name":"entityName",
"doc":"Input param entityName"
},
{
"type":"string",
"name":"aspectName",
"doc":"Input param aspectName"
},
{
"name":"filter",
"doc":"Input param filter.",
"optional":true,
"type":{
"namespace":"com.linkedin.metadata.query.filter",
"name":"Filter",
"doc":"The filter for finding a record or a collection of records",
"fields":[
{
"name":"or",
"doc":"A list of disjunctive criterion for the filter. (or operation to combine filters)",
"optional":true,
"type":{
"type":"array",
"items":{
"name":"ConjunctiveCriterion",
"doc":"A list of criterion and'd together.",
"fields":[
{
"type":{
"type":"array",
"items":{
"name":"Criterion",
"doc":"A criterion for matching a field with given value",
"fields":[
{
"type":"string",
"name":"field",
"doc":"The name of the field that the criterion refers to"
},
{
"type":"string",
"name":"value",
"doc":"The value of the intended field"
},
{
"name":"values",
"doc":"Values. one of which the intended field should match\nNote, if values is set, the above \"value\" field will be ignored",
"default":[
],
"type":{
"type":"array",
"items":"string"
}
},
{
"name":"condition",
"doc":"The condition for the criterion, e.g. EQUAL, START_WITH",
"default":"EQUAL",
"type":{
"name":"Condition",
"doc":"The matching condition in a filter criterion",
"type":"enum",
"symbolDocs":{
"IS_NULL":"Represent the relation: field is null, e.g. platform is null",
"IN":"Represent the relation: String field is one of the array values to, e.g. name in [\"Profile\", \"Event\"]",
"EQUAL":"Represent the relation: field = value, e.g. platform = hdfs",
"CONTAIN":"Represent the relation: String field contains value, e.g. name contains Profile",
"GREATER_THAN":"Represent the relation greater than, e.g. ownerCount > 5",
"LESS_THAN_OR_EQUAL_TO":"Represent the relation less than or equal to, e.g. ownerCount <= 3",
"START_WITH":"Represent the relation: String field starts with value, e.g. name starts with PageView",
"LESS_THAN":"Represent the relation less than, e.g. ownerCount < 3",
"GREATER_THAN_OR_EQUAL_TO":"Represent the relation greater than or equal to, e.g. ownerCount >= 5",
"END_WITH":"Represent the relation: String field ends with value, e.g. name ends with Event"
},
"symbols":[
"CONTAIN",
"END_WITH",
"EQUAL",
"IS_NULL",
"GREATER_THAN",
"GREATER_THAN_OR_EQUAL_TO",
"IN",
"LESS_THAN",
"LESS_THAN_OR_EQUAL_TO",
"START_WITH"
]
}
}
],
"type":"record"
}
},
"name":"and",
"doc":"A list of and criteria the filter applies to the query"
}
],
"type":"record"
}
}
},
{
"name":"criteria",
"doc":"Deprecated! A list of conjunctive criterion for the filter. If \"or\" field is provided, then this field is ignored.",
"optional":true,
"type":{
"type":"array",
"items":"Criterion"
}
}
],
"type":"record"
}
},
{
"name":"aggregationSpecs",
"doc":"Input param aggregated metrics.",
"optional":true,
"type":{
"type":"array",
"items":{
"namespace":"com.linkedin.timeseries",
"name":"AggregationSpec",
"doc":"Provides the aggregation specification on a member/field.",
"fields":[
{
"type":"string",
"name":"fieldPath",
"doc":"Name of the member/field."
},
{
"type":{
"name":"AggregationType",
"type":"enum",
"symbols":[
"LATEST",
"SUM",
"CARDINALITY"
]
},
"name":"aggregationType",
"doc":"Aggregation type for the metric."
}
],
"type":"record"
}
}
},
{
"type":{
"type":"array",
"items":{
"namespace":"com.linkedin.timeseries",
"name":"GroupingBucket",
"doc":"Defines the group by bucket definitions for time series requests.",
"fields":[
{
"type":{
"name":"GroupingBucketType",
"doc":"Defines a grouping bucket type.",
"type":"enum",
"symbols":[
"DATE_GROUPING_BUCKET",
"STRING_GROUPING_BUCKET"
]
},
"name":"type",
"doc":"Type of the grouping bucket."
},
{
"type":"string",
"name":"key",
"doc":"Key that specifies the column name to be used as the timestamp field for bucketing."
},
{
"name":"timeWindowSize",
"doc":"Bucket size (like a day/hour etc) for the date grouping buckets.",
"optional":true,
"type":{
"name":"TimeWindowSize",
"doc":"Defines the size of a time window.",
"fields":[
{
"type":{
"name":"CalendarInterval",
"type":"enum",
"symbols":[
"SECOND",
"MINUTE",
"HOUR",
"DAY",
"WEEK",
"MONTH",
"QUARTER",
"YEAR"
]
},
"name":"unit",
"doc":"Interval unit such as minute/hour/day etc."
},
{
"name":"multiple",
"doc":"How many units. Defaults to 1.",
"default":1,
"type":"int"
}
],
"type":"record"
}
}
],
"type":"record"
}
},
"name":"groupingBuckets",
"doc":"Input param groupingBuckets"
},
{
"type":{
"namespace":"com.linkedin.timeseries",
"name":"GenericTable",
"doc":"Defines a generic table.",
"fields":[
{
"type":{
"type":"array",
"items":"string"
},
"name":"columnNames",
"doc":"The names of the columns."
},
{
"type":{
"type":"array",
"items":"string"
},
"name":"columnTypes",
"doc":"The types of the columns."
},
{
"name":"rows",
"doc":"The data rows.",
"optional":true,
"type":{
"type":"array",
"items":{
"type":"array",
"items":"string"
}
}
}
],
"type":"record"
},
"name":"table",
"doc":"The results table."
},
{
"name":"lastUpdatedTimeMillis",
"doc":"When the index was last updated.",
"optional":true,
"type":"long"
}
],
"type":"record"
},
...
},
"resources":{
"com.linkedin.entity.entities":{
"schema":"com.linkedin.entity.Entity",
"namespace":"com.linkedin.entity",
"name":"entities",
"doc":"Single unified resource for fetching, updating, searching, & browsing DataHub entities\n\ngenerated from: com.linkedin.metadata.resources.entity.EntityResource",
"path":"/entities",
"collection":{
"supports":[
"batch_get",
"get"
],
"identifier":{
"type":"string",
"name":"entitiesId"
},
"actions":[
{
"name":"autocomplete",
"parameters":[
{
"type":"string",
"name":"entity"
},
{
"type":"string",
"name":"query"
},
{
"type":"string",
"name":"field",
"optional":true
},
{
"type":"com.linkedin.metadata.query.filter.Filter",
"name":"filter",
"optional":true
},
{
"type":"int",
"name":"limit"
}
],
"returns":"com.linkedin.metadata.query.AutoCompleteResult"
},
{
"name":"batchGetTotalEntityCount",
"parameters":[
{
"type":"{ \"type\" : \"array\", \"items\" : \"string\" }",
"name":"entities"
}
],
"returns":"{ \"type\" : \"map\", \"values\" : \"long\" }"
},
{
"name":"batchIngest",
"parameters":[
{
"type":"{ \"type\" : \"array\", \"items\" : \"com.linkedin.entity.Entity\" }",
"name":"entities"
},
{
"type":"{ \"type\" : \"array\", \"items\" : \"com.linkedin.mxe.SystemMetadata\" }",
"name":"systemMetadata",
"optional":true
}
]
},
{
"name":"browse",
"parameters":[
{
"type":"string",
"name":"entity"
},
{
"type":"string",
"name":"path"
},
{
"type":"com.linkedin.metadata.query.filter.Filter",
"name":"filter",
"optional":true
},
{
"type":"int",
"name":"start"
},
{
"type":"int",
"name":"limit"
}
],
"returns":"com.linkedin.metadata.browse.BrowseResult"
},
{
"name":"delete",
"parameters":[
{
"type":"string",
"name":"urn"
}
],
"returns":"com.linkedin.metadata.run.DeleteEntityResponse"
},
{
"name":"deleteAll",
"parameters":[
{
"type":"string",
"name":"registryId",
"optional":true
},
{
"type":"boolean",
"name":"dryRun",
"optional":true
}
],
"returns":"com.linkedin.metadata.run.RollbackResponse"
},
{
"name":"deleteReferences",
"parameters":[
{
"type":"string",
"name":"urn"
},
{
"type":"boolean",
"name":"dryRun",
"optional":true
}
],
"returns":"com.linkedin.metadata.run.DeleteReferencesResponse"
},
{
"name":"exists",
"parameters":[
{
"type":"string",
"name":"urn"
}
],
"returns":"boolean"
},
{
"name":"filter",
"parameters":[
{
"type":"string",
"name":"entity"
},
{
"type":"com.linkedin.metadata.query.filter.Filter",
"name":"filter"
},
{
"type":"com.linkedin.metadata.query.filter.SortCriterion",
"name":"sort",
"optional":true
},
{
"type":"int",
"name":"start"
},
{
"type":"int",
"name":"count"
}
],
"returns":"com.linkedin.metadata.search.SearchResult"
},
{
"name":"getBrowsePaths",
"parameters":[
{
"type":"com.linkedin.common.Urn",
"name":"urn"
}
],
"returns":"{ \"type\" : \"array\", \"items\" : \"string\" }"
},
{
"name":"getTotalEntityCount",
"parameters":[
{
"type":"string",
"name":"entity"
}
],
"returns":"long"
},
{
"name":"ingest",
"parameters":[
{
"type":"com.linkedin.entity.Entity",
"name":"entity"
},
{
"type":"com.linkedin.mxe.SystemMetadata",
"name":"systemMetadata",
"optional":true
}
]
},
{
"name":"list",
"parameters":[
{
"type":"string",
"name":"entity"
},
{
"type":"com.linkedin.metadata.query.filter.Filter",
"name":"filter",
"optional":true
},
{
"type":"com.linkedin.metadata.query.filter.SortCriterion",
"name":"sort",
"optional":true
},
{
"type":"int",
"name":"start"
},
{
"type":"int",
"name":"count"
}
],
"returns":"com.linkedin.metadata.query.ListResult"
},
{
"name":"listUrns",
"parameters":[
{
"type":"string",
"name":"entity"
},
{
"type":"int",
"name":"start"
},
{
"type":"int",
"name":"count"
}
],
"returns":"com.linkedin.metadata.query.ListUrnsResult"
},
{
"name":"search",
"parameters":[
{
"type":"string",
"name":"entity"
},
{
"type":"string",
"name":"input"
},
{
"type":"com.linkedin.metadata.query.filter.Filter",
"name":"filter",
"optional":true
},
{
"type":"com.linkedin.metadata.query.filter.SortCriterion",
"name":"sort",
"optional":true
},
{
"type":"int",
"name":"start"
},
{
"type":"int",
"name":"count"
}
],
"returns":"com.linkedin.metadata.search.SearchResult"
},
{
"name":"searchAcrossEntities",
"parameters":[
{
"type":"{ \"type\" : \"array\", \"items\" : \"string\" }",
"name":"entities",
"optional":true
},
{
"type":"string",
"name":"input"
},
{
"type":"com.linkedin.metadata.query.filter.Filter",
"name":"filter",
"optional":true
},
{
"type":"com.linkedin.metadata.query.filter.SortCriterion",
"name":"sort",
"optional":true
},
{
"type":"int",
"name":"start"
},
{
"type":"int",
"name":"count"
}
],
"returns":"com.linkedin.metadata.search.SearchResult"
},
{
"name":"searchAcrossLineage",
"parameters":[
{
"type":"string",
"name":"urn"
},
{
"type":"string",
"name":"direction"
},
{
"type":"{ \"type\" : \"array\", \"items\" : \"string\" }",
"name":"entities",
"optional":true
},
{
"type":"string",
"name":"input",
"optional":true
},
{
"type":"int",
"name":"maxHops",
"optional":true
},
{
"type":"com.linkedin.metadata.query.filter.Filter",
"name":"filter",
"optional":true
},
{
"type":"com.linkedin.metadata.query.filter.SortCriterion",
"name":"sort",
"optional":true
},
{
"type":"int",
"name":"start"
},
{
"type":"int",
"name":"count"
}
],
"returns":"com.linkedin.metadata.search.LineageSearchResult"
},
{
"name":"setWritable",
"parameters":[
{
"type":"boolean",
"name":"value",
"default":"true"
}
]
}
],
"entity":{
"path":"/entities/{entitiesId}"
},
"methods":[
{
"method":"get",
"parameters":[
{
"type":"{ \"type\" : \"array\", \"items\" : \"string\" }",
"name":"aspects",
"optional":true
}
],
"doc":"Retrieves the value for an entity that is made up of latest versions of specified aspects."
},
{
"method":"batch_get",
"parameters":[
{
"type":"{ \"type\" : \"array\", \"items\" : \"string\" }",
"name":"aspects",
"optional":true
}
]
}
]
}
},
...
Thank you in advance!

MongoDB query to include count of most frequent values for multiple fields

Thank you in advance for any help!
I've a collection QR with schema similar to this:
var qrSchema = new Schema({
qrId: { type: String, index: true },
owner: { type: Schema.Types.ObjectId, ref: 'User' },
qrName: { type: String },
qrCategory: { type: String, index: true },
shortUrl: { type: String}}
})
And collection Datas similar to this:
var dataSchema = new Schema({
qrId: { type: String, index: true}
city: { type: String},
device: { type: String},
date: { type: Date, index:true},
})
The relation between QR and Datas is 1-to-many.
I've an aggregate like this:
Model.QR.aggregate([
{ $match: {
$and: [
{ owner: mongoose.Types.ObjectId(user._id) },
{
$expr: {
$cond: [
{ $in: [ category, [ null, "", "undefined" ]] },
true,
{ $eq: [ "$qrCategory", category ] }
]
}
}
]
}
},
{ $lookup:
{
"from": "datas",
"localField": "qrId",
"foreignField": "qrId",
"as": "data"
}
},
{
$project: {
_id: 0,
qrId: 1,
qrName: 1,
qrCategory: 1,
shortUrl: 1,
data: {
$filter: {
input: "$data",
as: "item",
cond: {
$and: [
{ $gte: [ "$$item.date", date.start ] },
{ $lte: [ "$$item.date", date.end ] }
] }
}
}
}
},
{
$group: {
_id: { "qrId": "$qrId", "qrName": "$qrName", "qrCategory": "$qrCategory", "shortUrl": "$shortUrl" },
data: {
$push: {
dataItems: "$data",
count: {
$size: { '$ifNull': ['$data', []] }
}
}
}
}
},
{
$sort: {
"data.count": -1
}
},
{
$limit: 10,
}]).exec((err, results) => { })
Which is returning something like:
[
{
"_id": {
"qrId": "0PRA",
"qrName": "Campaign 0PRA",
"qrCategory": "html",
"shortUrl": "http://someurl.com/0PRA"
},
"data": [
{
"dataItems": [
{
"_id": "6200f2a8c0cf7a1c49233c7f",
"qrId": "0PRA",
"device": "iOS",
"city": "Beijing",
},
{
"_id": "6200f2eac0cf7a1c49233c80",
"qrId": "0PRA",
"device": "AndroidOS",
"city": "Beijing",
},
{
"_id": "6200f3a4c0cf7a1c49233c81",
"qrId": "0PRA",
"device": "AndroidOS",
"city": "Beijing",
},
{
"_id": "6200f632c0cf7a1c49233c88",
"qrId": "0PRA",
"device": "AndroidOS",
"city": "Nanchang",
},
{
"_id": "6201b342c0cf7a1c49233caa",
"qrId": "0PRA",
"device": "iOS",
"city": "Taizhou",
}
],
"count": 5
}
]
},
{
"_id": {
"qrId": "NQ17",
"qrName": "Campaign NQ17",
"qrCategory": "menu",
"shortUrl": "http://someurl.com/NQ17"
},
"data": [
{
"dataItems": [
{
"_id": "6200f207c0cf7a1c49233c7a",
"qrId": "NQ17",
"device": "iOS",
"city": "Singapore"
},
{
"_id": "8200f207c1cf7a1c49233c7a",
"qrId": "NQ17",
"device": "iOS",
"city": "Singapore"
},
{
"_id": "6200ac5db44f23b9ec2b6040",
"qrId": "NQ17",
"device": "AndroidOS",
"city": "San Antonio"
}
],
"count": 3
}
]
}
]
I'm trying to include the most frequent device and city in the results after the count of dataItems, like this:
[
{
"_id": {
"qrId": "0PRA",
"qrName": "Campaign 0PRA",
"qrCategory": "html",
"shortUrl": "http://someurl.com/0PRA"
},
"data": [
{
"dataItems": [
{
"_id": "6200f2a8c0cf7a1c49233c7f",
"qrId": "0PRA",
"device": "iOS",
"city": "Beijing",
},
{
"_id": "6200f2eac0cf7a1c49233c80",
"qrId": "0PRA",
"device": "AndroidOS",
"city": "Beijing",
},
{
"_id": "6200f3a4c0cf7a1c49233c81",
"qrId": "0PRA",
"device": "AndroidOS",
"city": "Beijing",
},
{
"_id": "6200f632c0cf7a1c49233c88",
"qrId": "0PRA",
"device": "AndroidOS",
"city": "Nanchang",
},
{
"_id": "6201b342c0cf7a1c49233caa",
"qrId": "0PRA",
"device": "iOS",
"city": "Taizhou",
}
],
"count": 5,
"topDevice": "AndroidOS", // <---- trying to add this
"topLocation": "Beijing" // <---- trying to add this
}
]
},
{
"_id": {
"qrId": "NQ17",
"qrName": "Campaign NQ17",
"qrCategory": "menu",
"shortUrl": "http://someurl.com/NQ17"
},
"data": [
{
"dataItems": [
{
"_id": "6200f207c0cf7a1c49233c7a",
"qrId": "NQ17",
"device": "iOS",
"city": "Singapore"
},
{
"_id": "8200f207c1cf7a1c49233c7a",
"qrId": "NQ17",
"device": "iOS",
"city": "Singapore"
},
{
"_id": "6200ac5db44f23b9ec2b6040",
"qrId": "NQ17",
"device": "android",
"city": "San Antonio"
}
],
"count": 3,
"topDevice": "iOS", // <---- trying to add this
"topLocation": "Singapore" // <---- trying to add this
}
]
}
]
Is this possible?
Thank you very much in advance for any help or hints!
Method 1
Use $function will be way more easier. MongoDB version >= 4.4
Sort function in js
db.collection.aggregate([
{
"$set": {
"data": {
"$map": {
"input": "$data",
"as": "d",
"in": {
"count": "$$d.count",
"dataItems": "$$d.dataItems",
"topDevice": {
$function: {
body: "function(arr) {return arr.sort((a,b) =>arr.filter(v => v===a).length-arr.filter(v => v===b).length).pop() }",
args: [ "$$d.dataItems.device" ],
lang: "js"
}
},
"topLocation": {
$function: {
body: "function(arr) {return arr.sort((a,b) =>arr.filter(v => v===a).length-arr.filter(v => v===b).length).pop() }",
args: [ "$$d.dataItems.city" ],
lang: "js"
}
}
}
}
}
}
}
])
mongoplayground
Method 2
db.qr.aggregate([
{
"$match": {
owner: {
"$in": [
"1",
"2"
]
}
}
},
{
"$lookup": {
"from": "data",
"localField": "qrId",
"foreignField": "qrId",
"as": "data",
"pipeline": [
{
"$match": {
"$and": [
{
"date": {
"$gte": ISODate("2021-09-01T01:23:25.184Z")
}
},
{
"date": {
"$lte": ISODate("2021-09-02T11:23:25.184Z")
}
}
]
}
},
{
"$facet": {
"deviceGroup": [
{
"$group": {
"_id": "$device",
"sum": {
"$sum": 1
}
}
},
{
"$sort": {
sum: -1
}
},
{
"$limit": 1
}
],
"cityGroup": [
{
"$group": {
"_id": "$city",
"sum": {
"$sum": 1
}
}
},
{
"$sort": {
sum: -1
}
},
{
"$limit": 1
}
],
"all": []
}
}
]
}
},
{
"$set": {
"data": {
"$first": "$data.all"
},
"topDevice": {
"$first": {
"$first": "$data.deviceGroup._id"
}
},
"topLocation": {
"$first": {
"$first": "$data.cityGroup._id"
}
}
}
},
{
$group: {
_id: {
"qrId": "$qrId",
"qrName": "$qrName",
"qrCategory": "$qrCategory",
"shortUrl": "$shortUrl"
},
data: {
$push: {
dataItems: "$data",
topDevice: "$topDevice",
topLocation: "$topLocation",
count: {
$size: {
"$ifNull": [
"$data",
[]
]
}
}
}
}
}
}
])
mongoplayground
Query
add the match you need, i didn't understand what the match should do
lookup on qrId
filter to keep only the start<=dates<=end (replace the 1 and 100)
facet to group all-documents, the topDevice the topLocation
$set to bring those data out from the nested locations they are
count is added as the size of all-documents
*maybe i am missing something, but try it(first part i think its like YuTing answer)
Test code here
QR.aggregate(
[{"$lookup":
{"from":"Datas",
"localField":"qrId",
"foreignField":"qrId",
"pipeline":
[{"$match":{"$and":[{"date":{"$gte":1}}, {"date":{"$lte":100}}]}},
{"$facet":
{"dataItems":[],
"topDevice":
[{"$group":{"_id":"$device", "count":{"$sum":1}}},
{"$sort":{"count":-1}}, {"$limit":1}],
"topLocation":
[{"$group":{"_id":"$city", "count":{"$sum":1}}},
{"$sort":{"count":-1}}, {"$limit":1}]}}],
"as":"data"}},
{"$set":{"data":{"$arrayElemAt":["$data", 0]}}},
{"$set":
{"dataItems":"$data.dataItems",
"count":{"$size":"$data.dataItems"},
"topDevice":
{"$getField":
{"field":"_id", "input":{"$arrayElemAt":["$data.topDevice", 0]}}},
"topLocation":
{"$getField":
{"field":"_id",
"input":{"$arrayElemAt":["$data.topLocation", 0]}}},
"data":"$$REMOVE"}}])

MongoDB $facet aggregation

I'm having a problem in my $facet aggregation. I want to know also if it is byAllProduct I will know that this product is the bestSeller, newlyAdded, and mostReviewed.
$facet: {
"byBestSeller": [
{ $sort: { "sold":-1 }},
{ $limit: 1 }
],
"byMostReviewed": [
{ $addFields: { "noOfReviews": {$size:"$reviews.message"}}},
{ $sort: { "noOfReviews":-1 }},
{ $limit: 1 }
],
"byNewlyAdded": [
{ $sort: { "createdAt":-1 }},
{ $limit: 1 }
],
"byAllProducts": [
{ $limit: 100 }
],
}
Now, my result is this.
"byBestSeller": [
{
"sold": 150,
"name": "Big Mac",
"shop": [
{
"name": "McDonald's"
}
],
"createdAt": {
"2020-05-11T01:55:17.623Z"
},
"reviews": [
{
"message": "Yummylicious"
},
{
"message": "Yummy burger"
}
]
}
],
"byMostReviewed": [
{
"sold": 100,
"name": "Spaghetti",
"shop": [
{
"name": "McDonald's"
}
],
"createdAt": {
"2020-06-11T01:55:17.623Z"
},
"reviews": [
{
"message": "Yummylicious"
},
{
"message": "Yummy Spaghetti"
},
{
"message": "Yummy super rich spag."
}
],
"noOfReviews": 3
}
],
"byNewlyArrived": [
{
"sold": 0,
"name": "Fries",
"shop": [
{
"name": "McDonald's"
}
],
"createdAt": {
"2020-7-11T01:55:17.623Z"
},
"reviews": [
{
"message": "Yummylicious"
},
]
}
],
"byAllProducts": [
{
"sold": 150,
"name": "Big Mac",
"shop": [
{
"name": "McDonald's"
}
],
"createdAt": {
"2020-05-11T01:55:17.623Z"
},
"reviews": [
{
"message": "Yummylicious"
},
{
"message": "Yummy burger"
}
]
}
{
"sold": 100,
"name": "Fries",
"shop": [
{
"name": "McDonald's"
}
],
"createdAt": {
"2020-06-11T01:55:17.623Z"
},
"reviews": [
{
"message": "Yummylicious"
},
{
"message": "Yummy Spaghetti"
},
{
"message": "Yummy super rich spag."
}
]
},
{
"sold": 0,
"name": "Fries",
"shop": [
{
"name": "McDonald's"
}
],
"createdAt": {
"2020-07-11T01:55:17.623Z"
},
"reviews": [
{
"message": "Yummylicious"
},
]
}
],
Is there a way so that even if it is included in all products I can know that it is the bestSeller, mostReviewed, and newlyarrived?

Application insights sink option not showing Performance counter in the Application insights for service fabric

Below is the configuration I have setup for Application Insights sink to send EtwEventSourceProviderConfiguration and EtwManifestProviderConfiguration and PerformanceCounters.
"WadCfg": {
"DiagnosticMonitorConfiguration": {
"overallQuotaInMB": "50000",
"sinks": "applicationInsights",
"EtwProviders": {
"EtwEventSourceProviderConfiguration": [
{
"provider": "Microsoft-ServiceFabric-Actors",
"scheduledTransferKeywordFilter": "1",
"scheduledTransferPeriod": "PT5M",
"DefaultEvents": {
"eventDestination": "ServiceFabricReliableActorEventTable"
}
},
{
"provider": "Microsoft-ServiceFabric-Services",
"scheduledTransferPeriod": "PT5M",
"DefaultEvents": {
"eventDestination": "ServiceFabricReliableServiceEventTable"
}
}
],
"EtwManifestProviderConfiguration": [
{
"provider": "cbd93bc2-xxxx-4566-b3a7-xxxxxxxx",
"scheduledTransferLogLevelFilter": "Information",
"scheduledTransferKeywordFilter": "4611686018427387904",
"scheduledTransferPeriod": "PT5M",
"DefaultEvents": {
"eventDestination": "ServiceFabricSystemEventTable"
}
}
]
},
"PerformanceCounters": {
"scheduledTransferPeriod": "PT1M",
"PerformanceCounterConfiguration": [
{
"counterSpecifier": "\\Processor(_Total)\\% Processor Time",
"sampleRate": "PT1M",
"unit": "Percent",
"sinks": "applicationInsights"
},
{
"counterSpecifier": "\\Process(My.WebAPI)\\Private Bytes",
"sampleRate": "PT1M",
"sinks": "applicationInsights"
}
]
}
},
"SinksConfig": {
"Sink": [
{
"name": "applicationInsights",
"ApplicationInsights": "d504ba9a-xxx-42b7-xxxx-xxxxxxxxxx"
},
{
"name": "MyApplicationInsightsProfilerSink",
"ApplicationInsightsProfiler": "d504ba9a-xxxx-42b7-xxxx-xxxxxxxxx"
}
]
}
},
"StorageAccount": "sfdgjsxxxxxxxxxxxx"
}
}
},
I do not see any of the events or performance counter in Log.