By your code, I can notice you are calling db.docs.aggregate(pipeline) in python. But you should not call it with db, just call it as docs.aggregate. Refer the following code:
pipeline = [
{"$unwind": "$COL"},
{"$group": {"_id": "$LOC", "sum": {"$sum": "$COL.amount"}}}
]
cursor = collection.aggregate(pipeline)
After that just convert the cursor to the list:
result = list(cursor)
If you are a beginner and want to know more about MongoDB then do check out the mongodb tutorial.
Also, have a look at this professional Full Stack Developer Training, designed to enhance your skills in the field.