Atlas search only return results where $lookup search matches?

Say I have two collections: orders and items. Orders can have 1 to many items, which orders has an array of item ids.

I have a page that shows all orders. I want to enable a search bar that allows users to search orders. Since my items are not embedded into the orders, I have to do a $lookup for the items.

I want the user to be able to search as if the items where embedded into the orders document.

Sample data:
Orders:

[
  { 
     _id: "1",
     buyer: "John doe",
     itemIds: ["1", "2"],
  },
   { 
     _id: "2",
     buyer: "Jane doe",
     itemIds: ["3"],
  }
]

Items:

[
  {
    _id: "1",
    name: "Shoe",
    description: "Red shoe"
  },
  {
    _id: "2",
    name: "Pants",
    description: "Blue Jeans"
  },
  {
    _id: "3",
    name: "Shirt",
    description: "White Tshirt"
  },
]

If the user searches “shoe”, it should return order 1
If the user searches “jane”, it should return order 2

Im trying to follow the $search $lookup documentation but don’t understand how to make it work for my use case: https://www.mongodb.com/docs/atlas/atlas-search/tutorial/lookup-with-search/

  • Use $search stage in the sub-pipeline to search for customer accounts that must have purchased both CurrencyService and InvestmentStock with preference for an order limit between 5000 to 10000.

My recommended approach is to actually embed the searchable product details into the Orders collection. It’s duplication, but it’s also a snapshot for when the Items change descriptions after purchased, so the user is only searching on the text current at time of purchase.