Can you please guide me how we can set variables in mongodb native queries?
you suggested me -
Try making a query in the GUI with a filter, and then convert to Native query. It's much easier to learn from looking at real examples.
So here I have attached a simple native converted query
[
{
"$match": {
"$and": [
{
"linkedin_response.is_poi": true
},
{
"linkedin_response.archive": false
}
]
}
},
{
"$group": {
"_id": {
"created_at~~~week": {
"$let": {
"vars": {
"parts": {
"$dateToParts": {
"timezone": "GMT",
"date": {
"$subtract": [
"$created_at",
{
"$multiply": [
{
"$subtract": [
{
"$let": {
"vars": {
"day_of_week": {
"$mod": [
{
"$add": [
{
"$dayOfWeek": "$created_at"
},
6
]
},
7
]
}
},
"in": {
"$cond": {
"if": {
"$eq": [
"$day_of_week",
0
]
},
"then": 7,
"else": "$day_of_week"
}
}
}
},
1
]
},
86400000
]
}
]
}
}
}
},
"in": {
"$dateFromParts": {
"timezone": "GMT",
"year": "$parts.year",
"month": "$parts.month",
"day": "$parts.day"
}
}
}
}
},
"avg": {
"$avg": "$total_score"
}
}
},
{
"$sort": {
"_id": 1
}
},
{
"$project": {
"_id": false,
"created_at~~~week": "$_id.created_at~~~week",
"avg": true
}
},
{
"$sort": {
"created_at~~~week": 1
}
}
]
please suggest me where I should put {{}} for making "created_at " variable. So that I can use it as a filter in my dashboards.
Diagnostic Info-
{
"browser-info": {
"language": "en-GB",
"platform": "MacIntel",
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36",
"vendor": "Google Inc."
}
}