How to construct redact query in python

I am very new to mongodb and python. I tried to write a redact query but having issue. It works in Mongo Shell but not in python. Can someone help? TIA

userAccess = [ "deserunt sint cupidata" ,"dolore pariatur aliqua","eu magna cupidatat dolore","amet irure nulla"]

cursor =
     { "$redact": {
        "$cond": {
           "if": { '$gt': 
                    { "$size": 
                     { "$setIntersection": 
                      [ "$tags", userAccess ] 
                     } }, 0 ] 
           then: "$$DESCEND",
           "else": "$$PRUNE"

for x in cursor:

Hi @Tony_Tran

A quick approach to getting valid code for an aggregation is to use MongoDB’s Compass tool where you can input the Mongo Shell syntax and then export a specific language’s code, say Python. This is probably the quickest and easiest way to debug your current problem.

In general, this type of broader question outside of a relevant lesson should be asked in the Drivers & ODM category so you can more expose for your question as questions in this category are meant to be related to lessons and exercises within M220P.

Hope this helps.