sql >> Base de Datos >  >> NoSQL >> MongoDB

Pymongo devuelve valores solo como lista

Simplemente hazlo así:

cursor = collection.aggregate([
    {"$match": {"current_strategy": "PPStrategy4016"}},
    {"$group": {
        "_id": None, 
        "myFundsChange": {"$push": "$myFundsChange"}
    }}
])

Luego puede consumir el cursor usando un bucle for tradicional o simplemente.

for res in cursor:
    # do something with the result.

Tenga en cuenta que el Cursor objeto contiene un documento aquí porque agrupamos por None