Load the practice collection
Run once in mongosh against a development instance with an empty skillMatches practice collection.
const lab = db.getSiblingDB("keplergrid_practice")
lab.skillMatches.insertMany([
{ _id: "profile-a", requested: ["sql", "python"], offered: ["sql", "sql", "go"] },
{ _id: "profile-b", requested: ["sql", "python"], offered: ["go"] },
{ _id: "profile-c", requested: ["sql", "python"] }
])
In KeplerGrid, open keplergrid_practice.skillMatches with a Read only connection.
Compute the shared skills and count them
Paste into Aggregation → JSON and run the pipeline. Here a missing or null array means the same thing as an empty list.
[
{ "$set": { "sharedSkills": {
"$setIntersection": [
{ "$ifNull": ["$requested", []] },
{ "$ifNull": ["$offered", []] }
]
} } },
{ "$set": { "matchCount": { "$size": "$sharedSkills" } } },
{ "$sort": { "_id": 1 } }
]
profile-a returns ["sql"] with a count of one. The repeated sql counts once. The two remaining profiles return empty arrays with a count of zero.
Treat the result as a set
The intersection does not guarantee an output order or descend into nested arrays. Sort the resulting array for display when order matters. Normalize inconsistent spelling or case before comparing when those differences should be ignored.
See how to sort the resulting array for display or revisit the related KeplerGrid walkthrough.