Database

db={"items":[{"item_code":"A001","tax_category_code":"T001","price":98},{"item_code":"A002","tax_category_code":"T002","price":39},{"item_code":"A003","tax_category_code":"T001","price":77},{"item_code":"A004","tax_category_code":"T003","price":52}],"tax_schema":[{"status":"active","categories":[{"tax_category_code":"T001","priority":1,"percentage":0.1},{"tax_category_code":"T002","priority":3,"percentage":0.5},{"tax_category_code":"T003","priority":2,"percentage":0.87}],"date":"2022-11-24T00:00:00-05:00"},{"status":"inactive","categories":[{"tax_category_code":"T001","priority":0,"percentage":0.08},{"tax_category_code":"T002","priority":2,"percentage":0.42},{"tax_category_code":"T003","priority":4,"percentage":0.74}],"date":"2022-06-06T00:00:00-05:00"},{"status":"inactive","categories":[{"tax_category_code":"T001","priority":0,"percentage":0.05},{"tax_category_code":"T002","priority":0,"percentage":0.41},{"tax_category_code":"T003","priority":0,"percentage":0.72}],"date":"2022-03-31T00:00:00-05:00"}]}

Query

db.items.aggregate([{"$lookup":{"from":"tax_schema",let:{tcc:"$tax_category_code"},pipeline:[{$match:{"status":"active"}},{"$unwind":"$categories"},{$match:{$expr:{$eq:["$$tcc","$categories.tax_category_code"]}}}],"as":"tax_schema"}},{$project:{item_code:1,tax_category_code:1,price:1,tax_schema_category:{$arrayElemAt:["$tax_schema.categories",0]},}}])

Result