pass value from different Collection inside subquery in Match operation in Mongodb - mongodb-query

I have 2 collection: Company and Stores. I used $lookup on Store collection using the storeIds on Company collection. I need to pass 'Company.Year' value to Stores.Statuses.Year inside $Match operator. Any help is appreciated.
Company: [
{
"_id": {
"$oid": "1388445c0000000000000001"
},
"name": "Company A",
"year": 2022,
"storeIds": [
{
"$oid": "1388445c0000000000000011"
},
{
"$oid": "1388445c0000000000000012"
}
]
}
]
Store: [
{
"_id": {
"$oid": "1388445c0000000000000011"
},
"name": "Store A",
"statuses": [
{
"year": 2021,
"status": "pending"
},
{
"year": 2022,
"status": "review"
}
]
}
]
Output: [
{
"_id": {
"$oid": "1388445c0000000000000001"
},
"name": "Company A",
"year": 2022,
"storeIds": [
{
"$oid": "1388445c0000000000000011"
}
],
"statuses": [
{
"year": 2022,--->How to pass company.year value instead of hard-coded value(2022).
"status": "review"
}
]
}
]

Related

Shopware 6 API / Product Listing / How to add available color variants for each product on the response

API Request
/store-api/product-listing/{categoryId}
I want each product in the API response to have available color variants. Because I want to show color variants on the product list page. But currently this data is not provided by the shopware 6 api.
I've tried to add this data by using associations but it didnt help.
Request Body
{
"includes": {
"product": ["id", "productNumber", "cover", "options"]
},
"associations": {
"options": {
"media": []
}
}
}
The request body looks to be correct. If the product is a variant then it should have content for options.
To verify try the following request body:
{
"limit": 1,
"includes": {
"product": ["id", "productNumber", "options"],
"property_group_option": ["name", "group"],
"property_group": ["name"]
},
"associations": {
"options": {
"associations": {
"group": []
}
}
},
"filters": [
{
"type": "not",
"operator": "and",
"queries": [
{
"type": "equals",
"field": "parentId",
"value": null
}
]
}
]
}
This should yield a single variant.
Response should look similar to this:
{
"entity": "product",
"total": 1,
"aggregations": [],
"page": 1,
"limit": 1,
"elements": [
{
"productNumber": "10042.1",
"options": [
{
"name": "linen",
"group": {
"name": "textile",
"apiAlias": "property_group"
},
"apiAlias": "property_group_option"
},
{
"name": "35",
"group": {
"name": "size",
"apiAlias": "property_group"
},
"apiAlias": "property_group_option"
},
{
"name": "chartreuse",
"group": {
"name": "shirt-color",
"apiAlias": "property_group"
},
"apiAlias": "property_group_option"
}
],
"id": "0002ea44c49c41ecb91c43e7e49e422d",
"apiAlias": "product"
}
],
"states": [],
"apiAlias": "dal_entity_search_result"
}

How to apply filter for nested arrays in mulesoft dataWeave

I tried to filter below json payload characters[] array which is having result as 'valid' and data[] array name as 'WBB' and priority as '1'
I tried below code but not working can some one help me ?.
flatten(payload.offers.category.characters) filter ((item, index) -> item.result=='valid' and flatten(item.data) filter ((item, index) -> item.name=='WBB' and item.priority==1))
Json payload
{
"offers": [
{
"id": 100,
"name": "Test1",
"category": {
"characters": [
{
"result": "valid",
"data": [
{
"name": "WBB",
"priority": 1
},
{
"name": "ILL",
"priority": 2
}
]
}
]
}
},
{
"id": 200,
"name": "Test2",
"category": {
"characters": [
{
"data": [
{
"name": "ISS",
"priority": 1
},
{
"name": "ILL",
"priority": 2
}
]
}
]
}
},
{
"id": 300,
"name": "Test3",
"category": {
"characters": [
{
"data": [
{
"name": "WSS",
"priority": 1
},
{
"name": "ILL",
"priority": 2
}
]
}
]
}
}
]
}
Expected payload
[
{
"name": "WBB",
"priority": 1
}
]
flatten((flatten(payload.offers..characters) filter $.result == "valid").data) filter ($.name=="WBB" and $.priority == 1)
flatten(payload..data) filter ((item, index) -> item.name == 'WBB' )

Xero Profit and Loss API - Parse JSON response to SQL Table not working

I am working in ASP .Net MVC, i used Xero nugut package to call api, i can not able to parse json Response .
`I am stuck on how to expand the JSON lists of arrays as columns instead of rows. Please help to retrive data from json to SQL table or in C#, Also i want to display report in html form with this data.
List in Header row Cells column
List in the two Section rows Rows.1 column
Any tips, hints, ideas, pointers?
{
"Reports": [
{
"ReportID": "ProfitAndLoss",
"ReportName": "Profit and Loss",
"ReportType": "ProfitAndLoss",
"ReportTitles": [
"Profit & Loss",
"Demo Company (AU)",
"1 February 2018 to 28 February 2018"
],
"ReportDate": "25 February 2018",
"UpdatedDateUTC": "\/Date(1519593468971)\/",
"Rows": [
{
"RowType": "Header",
"Cells": [
{ "Value": "" },
{ "Value": "28 Feb 18" },
{ "Value": "28 Jan 18" }
]
},
{
"RowType": "Section",
"Title": " Income",
"Rows": [
{
"RowType": "Row",
"Cells": [
{
"Value": "Sales",
"Attributes": [
{
"Value": "e2bacdc6-2006-43c2-a5da-3c0e5f43b452",
"Id": "account"
}
]
},{
"Value": "9220.05",
"Attributes": [
{
"Value": "e2bacdc6-2006-43c2-a5da-3c0e5f43b452",
"Id": "account"
}
]
},{
"Value": "5120.05",
"Attributes": [
{
"Value": "e2bacdc6-2006-43c2-a5da-3c0e5f43b452",
"Id": "account"
}
]
}
]
},
{
"RowType": "SummaryRow",
"Cells": [
{ "Value": "Total Income" },
{ "Value": "9220.05" },
{ "Value": "1250.09" }
]
}
]
},{
"RowType": "Section",
"Rows": [
{
"RowType": "Row",
"Cells": [
{ "Value": "NET PROFIT" },
{ "Value": "-6250.09" },
{ "Value": "-7250.09" }
]
}
]
}
]
}
]
}
`

aggregate in mongodb left join with $lookup

I have three collections
posts=[
{
"id": "p1",
"title": "title 1"
},
{
"id": "p2",
"title": "title 2"
}]
users = [
{
"id": "u1",
"name": "name1"
},
{
"id": "u2",
"name": "name2"
}]
comments = [
{
"userId": "u1",
"postId": "p1",
"comment": "comment 1"
}]
I want to get all collection posts and comments in each post by userId(u1) as:
posts=[
{
"id": "p1",
"title": "title 1",
"comments":[
"userId": "u1",
"comment": "comment 1"
]
},
{
"id": "p2",
"title": "title 2",
"comments":[]
}]
I used aggregate function and $lookup operator but I don't know using the $match operator to filter userId. I used aggregate bellow:
self.db.posts.aggregate([
{
"$lookup":{
"from": "comments",
"localField": "id",
"foreignField": "postId",
"as": "comments",
}
},
{
"$match":{
"comments.userId": {"$eq": param.objectUserId}
},
},
{"$skip": (param.page - 1) * param.pageSize},
{"$limit": param.pageSize},
{"$sort": {"unixDate": pymongo.DESCENDING}}
])
It only return one post in array corresponding with userId="u1"
Please help me!
Thank all!
You have to make use of the pipeline option of $lookup stage and pass the additional conditions that you want to apply.
db.posts.aggregate([
{
"$lookup": {
"from": "comments",
"let": {
"pId": "$id"
},
"pipeline": [
{
"$match": {
"$expr": {
"$eq": [
"$postId",
"$$pId"
],
},
"userId": "u1",
},
},
{
"$project": {
"_id": 0,
"userId": 1,
"comment": 1,
},
},
],
"as": "comments"
}
}
])
Mongo Playground Sample Execution
self.db.posts.aggregate([
{
"$lookup": {
"from": "comments",
"let": {
"pId": "$id"
},
"pipeline": [
{
"$match": {
"$expr": {
"$eq": [
"$postId",
"$$pId"
],
},
"userId": param.objectUserId,
},
},
{
"$project": {
"_id": 0,
"userId": 1,
"comment": 1,
},
},
],
"as": "comments"
}
},
{"$skip": (param.page - 1) * param.pageSize},
{"$limit": param.pageSize},
{"$sort": {"unixDate": pymongo.DESCENDING}}
])

How to expand tree node without ajax request?

I am using Extjs tree, i got problem with click on nested node ajax request to server, i know this kind of lazy load but my tree is not big, around 35 items so i want request to server time only to collect all tree node and items.
Any idea?
View:
Ext.define('CRM.view.role.RoleTree' ,{
extend: 'Ext.tree.Panel',
alias: 'widget.roleTreeList',
id:'tree-role-panel',
split: false,
autoScroll: true,
lines: true,
singleExpand: false,
store: 'RoleList'
})
Store:
Ext.define('CRM.store.RoleList', {
extend: 'Ext.data.TreeStore',
storeId: 'RoleTreeStoreId',
//model: 'CRM.model.RoleList',
autoLoad: false,
proxy: {
type : 'ajax',
url : 'index.php/role/getRoleList',
async : false,
reader: {
type : 'json',
method : 'POST'
}
},
root:{
expanded:true,
text:"Organization",
leaf:'false',
id : '/',
}
})
Json return:
{
"text": "Organization",
"id": "role-1",
"children": [
{
"text": "Admin",
"id": "role-12",
"expanded": "true",
"children": [
{
"text": "MSD",
"id": "role-23",
"children": [
{
"text": "Customer Care Manager",
"id": "role-4",
"children": [
{
"text": "Customer Care Adviser",
"id": "role-5"
}
]
},
{
"text": "Solution Adviser",
"id": "role-7"
},
{
"text": "Sales Manager",
"id": "role-31",
"children": [
{
"text": "Solution Sales",
"id": "role-6"
},
{
"text": "Teritory 01 - Safy",
"id": "role-9",
"children": [
{
"text": "Sales Person 01",
"id": "role-10"
},
{
"text": "Sales Trainee 01",
"id": "role-26"
}
]
},
{
"text": "Teritory 3 - Sambo",
"id": "role-11",
"children": [
{
"text": "Sales Person 3",
"id": "role-13"
}
]
},
{
"text": "Teritory 4 - Narong",
"id": "role-14",
"children": [
{
"text": "Sales Team 4",
"id": "role-15",
"children": [
{
"text": "Sales Person 4",
"id": "role-25"
}
]
}
]
},
{
"text": "branch shv",
"id": "role-16",
"children": [
{
"text": "sales shv",
"id": "role-19"
}
]
},
{
"text": "branch btb",
"id": "role-17",
"children": [
{
"text": "sales btb",
"id": "role-20"
}
]
},
{
"text": "branch srp",
"id": "role-18",
"children": [
{
"text": "sales srp",
"id": "role-21",
"children": [
{
"text": "sales person srp",
"id": "role-28"
}
]
}
]
},
{
"text": "Retention Program",
"id": "role-22",
"children": [
{
"text": "Retention Program Analysist",
"id": "role-24"
}
]
},
{
"text": "Sales Trainee",
"id": "role-27"
},
{
"text": "Enterprise Sales Engineer",
"id": "role-29"
},
{
"text": "Meas Test",
"id": "role-30"
},
{
"text": "Teritory 02 - Kol",
"id": "role-32",
"children": [
{
"text": "Sales Person 02",
"id": "role-8"
}
]
}
]
}
]
},
{
"text": "CTO",
"id": "role-35",
"children": [
{
"text": "Support Manager",
"id": "role-2",
"children": [
{
"text": "Technical Support Adviser",
"id": "role-3"
}
]
},
{
"text": "IT BIlling Product Manager",
"id": "role-33",
"children": [
{
"text": "IT Staff",
"id": "role-34"
}
]
}
]
},
{
"text": "Business Consultant",
"id": "role-36"
}
]
}
]
}
You can still use asynchronous call, but only once. To make sure only one call is made, return all children in first call. Extjs will load all children provided.
I found my mistake with JSON, i should add property "leaf = true/false" according has child or hasn't.