pymongo aggregate collection keys

Using this answer here https://stackoverflow.com/a/43570730/7626649

I'd like to do this with flask-pymongo.

Specifically I'd like to perform the below query in flask-pymongo and/or pymongo (It seems like if it can be done in one then it could be done in the other..I hope):

db.things.aggregate([
  {"$project":{"arrayofkeyvalue":{"$objectToArray":"$$ROOT"}}},
  {"$unwind":"$arrayofkeyvalue"},
  {"$group":{"_id":null,"allkeys":{"$addToSet":"$arrayofkeyvalue.k"}}}
])

Here's what I've done so far:

pipeline = [
    {"$project":{"arrayofkeyvalue":{"$objectToArray":"$$ROOT"}}},   
    {"$unwind":"$arrayofkeyvalue"},
    {"$group":{"_id": None,"allkeys":{"$addToSet":"$arrayofkeyvalue.k"}}}   
]

print(list(MYDB.db.things.aggregate(pipeline)))

I get an empty list as the result with no errors.