Utopia Knowledge Base Definitions
  • Welcome to Utopia University
  • 🔦Overview
    • How to Navigate the University
    • How is Utopia different
    • Features
    • Utopia Sync Website Links
  • 😁Contact Us
    • Open Chat Room
    • Contact Us
  • ⬇️Installation guide
    • Docker Compose Installation
      • Prerequisites
      • The Installation Configurator
        • Databases
        • S3 (Optional)
        • SMTP Details (Compulsory)
        • Adobe API Credentials (Optional)
        • Final steps to get your compose fle
      • Compose Installation
    • Kubernetes Installation
      • Prerequisites
      • The Installation Configurator
        • Databases
        • S3 (Optional)
        • SMTP Details (Compulsory)
        • Adobe API Credentials (Optional)
        • Ingress Naming (Compulsory)
        • Final steps to get helm chart
      • Using Helm to Install and Edit
      • Final Stage DNS setup
        • Setting up TLS cert
        • Third Party Service DNS Manager (like Cloudflare)
        • DNS Work-around while you get your cert ready
    • Cluster Craft
      • Basic Kubernetes install with microk8s
      • Basic Kubernetes install with microk8s and NFS storage
      • Updating Loadbalancer IP with Microk8s and Metallb
      • Installing Utopia in Azure
      • Testing SMTP server from a Kubernetes Cluster or a Container using telnet and openssl
      • Kubernetes Visibility
        • Kube CLI visibility with Lens or OpenLens
        • Prometheus and Grafana Monitoring
      • Syntax Cheat Sheet
        • Kubectl
        • Microk8s
        • Microceph
        • Mongodb Compass
          • _MONGOSH Terminal Commands
          • Query Commands
        • Shell Commands
  • 🖥️Product Guide
    • Integration Hub
      • Selecting your Organization
      • Menu Navigation
      • Data In
        • Collection Parameters
        • Document Lifespan Strategy
        • Source Connectors
          • Connector Modules
            • Empact Email Orders
            • File Transfer Protocol (FTP)
            • Generate Random Documents (Test)
            • HTTP REST Collection Source
            • Lotus 1-2-3 prn file
            • Microsoft Navision Collection
            • MySQL Query
            • Pick n Pay Supplier Orders
            • Post Office Protocol (POP3)
            • Secure File Transfer Protocol (SFTP) (SSH)
            • Internet Message Access Protocol (IMAP)
            • Shoprite Collection
            • SQL Server Query
            • StrategixNav Collection
            • Transaction Query
          • Web Hook Triggers
        • API Listeners
          • Document Capture
          • Document Query (External)
          • Document Query (Integrated)
          • Listener Security
      • Transform
        • Search Documents
        • The Designer Panel
        • The Designer view
        • Transform Stage Types
          • Filter
          • Lookup
          • Add Field
          • Projection
          • Unwind
          • JS / JSON
      • Data Out
        • Publisher Collection Parameters
        • Data Out Connector
          • API Collection Publisher
          • Do Nothing
          • File Transfer Protocol (FTP)
          • HTTP REST Collection Publisher
          • Message Transport Post
          • Microsoft Navision Publisher
          • PDF Document Emailer
          • Pick n Pay Invoices
          • Post Syspro QueryQuery
          • Post Syspro Transaction
          • Post Vector Orders
          • Secure File Transform Protocol (SFTP) (SSH)
          • Shoprite Invoice Publisher
          • SMTP Collection Publisher
          • SQL Server OPENJSON Publisher
          • SQL Server Query Publisher
          • StrategixNav Publisher
      • Validation
    • Organizations
    • Transaction Page
    • User Profile
    • Logging
    • Process Que Dashboard
    • Process Error Dashboard
    • New Functions
      • XML to Json using the Transform Designer
      • XML to Json using ChatGPT
      • Rest Connector JS Prescript
    • Release Notes
      • Microservices
        • 0.12.1622
        • 0.12.1630
  • ☕Use Cases
    • Follow Along Examples
      • Look-ups! no-code Transform Stage
        • Multi Field Look-ups! low-code Transform Stage
      • Rest Connector JS Prescript Example
        • Rest Connector JS PreScript Fault Finding Techniques
      • XML to Json using the Transform Designer
      • XML to Json using ChatGPT
    • Solution Discussions
      • Moditar: Increasing Integration Adoption using UtopiaSync
      • UtopiaSync the scalable no-code Backend?
      • UtopiaSync Security - How does it work?
      • UtopiaSync Custom Configuration
      • UtopiaSync Maintenance
  • 😁Case Studies
    • How Moditar drove efficiency for Meridian Wine Merchants using Utopia iPaaS
    • The journey to Spier Wine Farm's perfect eCommerce Integration
    • Integration journey to 100% automated with La Concorde Bakery
Powered by GitBook
On this page
  1. Use Cases
  2. Follow Along Examples
  3. Look-ups! no-code Transform Stage

Multi Field Look-ups! low-code Transform Stage

PreviousLook-ups! no-code Transform StageNextRest Connector JS Prescript Example

Last updated 1 year ago

In the we looked at using the no-code tools to build a lookup stage. This has its limitations so here we are going to look at elaborating this into a low-code stage where we can do a lookup to match 2 fields using a mongodb aggregation. Please see the previous example for all the input files required for this tutorial.

To do this, the only extra information we will need will be to get the collection ID of the PriceMapping collection, so lets go back into the Integration Hub and edit that collection.

Here is the collection ID! lets copy that and save it to a notepad.

Next step is to get the document format from this collection, I am just going to download it from the transaction page. On the transaction page expand one of the PriceMapping entries (where it says 3) this will expand and show you all the documents that we un-batched. click the menu button, and view one of these entries. Now hit the download button to save it to your hard-drive.

To do this I am going to give it the Cafe Orders In collection json format, the fields I want to match and the format of the lookup collection along with its ID. Important to ask it to give you the output in a valid JSON format.

My Prompt, I then attached the two files referenced:

I need to a mongodb aggregation written in valid json format. This aggregation needs to take document: Orders_In.json and do a lookup from collection 'e7cf6211-6154-44dd-a3eb-896cfc7380ce' which contains documents with format PriceMapping.json. 

The lookup must match AccountNumber with CustomerCode and then OrderItems.ItemNumber with ProductCode.

The output should add the matched document to a field within OrderItems called PriceLookup, there should be a response for each OrderItems.

It has given the the following code

[
  {
    "$unwind": "$OrderItems"
  },
  {
    "$lookup": {
      "from": "e7cf6211-6154-44dd-a3eb-896cfc7380ce",
      "let": {
        "accountNumber": "$AccountNumber",
        "itemNumber": "$OrderItems.ItemNumber"
      },
      "pipeline": [
        {
          "$match": {
            "$expr": {
              "$and": [
                { "$eq": ["$CustomerCode", "$$accountNumber"] },
                { "$eq": ["$ProductCode", "$$itemNumber"] }
              ]
            }
          }
        }
      ],
      "as": "OrderItems.PriceLookup"
    }
  },
  {
    "$unwind": "$OrderItems.PriceLookup"
  },
  {
    "$group": {
      "_id": "$_id",
      "CartID": { "$first": "$CartID" },
      "TransactionReference": { "$first": "$TransactionReference" },
      "OrderReference": { "$first": "$OrderReference" },
      "OrderNumber": { "$first": "$OrderNumber" },
      "InvoiceName": { "$first": "$InvoiceName" },
      "InvoiceCity": { "$first": "$InvoiceCity" },
      "InvoiceCountry": { "$first": "$InvoiceCountry" },
      "InvoiceAddress1": { "$first": "$InvoiceAddress1" },
      "OrderDate": { "$first": "$OrderDate" },
      "OrderTotal": { "$first": "$OrderTotal" },
      "AccountNumber": { "$first": "$AccountNumber" },
      "OrderStatus": { "$first": "$OrderStatus" },
      "CurrencyCode": { "$first": "$CurrencyCode" },
      "TotalLines": { "$first": "$TotalLines" },
      "OrderItems": { "$push": "$OrderItems" }
    }
  }
]

I am going to paste this into transform stage, changing its type to js/json

Great we have success, the output now only has the correct data matching

This new stage looks great, it just has some unwanted system fields in there which we do not need for this scenario, such as _id and header fields. So we just need to remove those from the file, I am just going to ask AI to remove them

The output is correct except inside the OrderItems.PriceLookup result, it contains _id and _header fields from the lookup document which are not needed. please remove these.

I got another response, which I tested and got an elmah error. NB: remove comments from the document before pasting it into UtopiaSync JS/JSON stage. Jumped into Elmah to get the error and found it. Prompted AI again

OK I am getting an error: Invalid $project :: caused by :: Cannot do inclusion on field CustomerCode in exclusion projection

Tried the next code and SUCCESS!

[
  {
    "$unwind": "$OrderItems"
  },
  {
    "$lookup": {
      "from": "e7cf6211-6154-44dd-a3eb-896cfc7380ce",
      "let": {
        "accountNumber": "$AccountNumber",
        "itemNumber": "$OrderItems.ItemNumber"
      },
      "pipeline": [
        {
          "$match": {
            "$expr": {
              "$and": [
                { "$eq": ["$CustomerCode", "$$accountNumber"] },
                { "$eq": ["$ProductCode", "$$itemNumber"] }
              ]
            }
          }
        },
        {
          "$project": {
            "_id": 0,
            "_header": 0
          }
        }
      ],
      "as": "OrderItems.PriceLookup"
    }
  },
  {
    "$unwind": "$OrderItems.PriceLookup"
  },
  {
    "$group": {
      "_id": "$_id",
      "CartID": { "$first": "$CartID" },
      "TransactionReference": { "$first": "$TransactionReference" },
      "OrderReference": { "$first": "$OrderReference" },
      "OrderNumber": { "$first": "$OrderNumber" },
      "InvoiceName": { "$first": "$InvoiceName" },
      "InvoiceCity": { "$first": "$InvoiceCity" },
      "InvoiceCountry": { "$first": "$InvoiceCountry" },
      "InvoiceAddress1": { "$first": "$InvoiceAddress1" },
      "OrderDate": { "$first": "$OrderDate" },
      "OrderTotal": { "$first": "$OrderTotal" },
      "AccountNumber": { "$first": "$AccountNumber" },
      "OrderStatus": { "$first": "$OrderStatus" },
      "CurrencyCode": { "$first": "$CurrencyCode" },
      "TotalLines": { "$first": "$TotalLines" },
      "OrderItems": { "$push": "$OrderItems" }
    }
  }
]

Check out the response on the Designer:

We now have an accurate multi field lookup ready for use!

I hope this tutorial was helpful, help us out and let us know what you would like to see next!

now you can take a look , and navigate the syntax to build the aggregation yourself, but I am going to be lazy and just ask AI to do it for me.

☕
here
previous Example