Document Query (Integrated)

A end point with a query set behind it; using this query a pre-defined query can be built behind the endpoint in Utopia. External systems can then service the end point with optional parameters and the results can be served accordingly. The below is a fairly complex query example, here the api will be expecting add parameters “CustomerCode” and “PriceListID” to their GET call, Utopia will then receive the parameters and execute the Pipeline. The Parameters get specified at the end. If this looks a bit intimidating, please see our examples area for other examples.

{
  "Aggregate": {
    "Pipeline": [
      {
        "$match": {
          "CustomerCode": "${CustomerCode}"
        }
      },
      {
        "$unwind": {
          "path": "$Items"
        }
      },
      {
        "$group": {
          "_id": "$Items.ProductCode",
          "Count": {
            "$sum": 1
          }
        }
      },
      {
        "$sort": {
          "Count": -1
        }
      },
      {
        "$lookup": {
          "from": "4e9c1234-a140-42ec-a904-abcd562eacb9",
          "localField": "_id",
          "foreignField": "ProductCode",
          "as": "string"
        }
      },
      {
        "$unwind": {
          "path": "$string"
        }
      },
      {
        "$project": {
          "_id": 0,
          "PriceListID": "$string.PriceListID",
          "ProductCode": "$string.ProductCode",
          "ProductName": "$string.ProductName",
          "Active": "$string.Active"
        }
      },
      {
        "$match": {
          "$expr": {
            "$eq": [
              "$PriceListID",
              {
                "$toInt": "${PriceListID}"
              }
            ]
          }
        }
      },
      {
        "$limit": 5
      }
    ]
  },
  "Parameters": {
    "CustomerCode": {
      "DefaultValue": "0"
    },
    "PriceListID": {
      "DefaultValue": 0
    }
  }
}

Last updated