0

I am using the aggregation pipeline below which results in success with pymongo itself. With mongomock there is the error message TypeError: int() argument must be a string, a bytes-like object or a real number, not 'datetime.datetime'. Is this a limitation of mongomock encountered here?

[
    {
        "$match": {
            "$and": [
                {"topic_name": "door"},
                {"internal_id": "7XXXXX"},
                {"payload.ts": {"$gte": datetime.datetime(2023, 4, 11, 0, 0), "$lte": datetime.datetime(2023, 4, 13, 0, 0)}},
            ]
        }
    },
    {"$sort": {"payload.ts": -1}},
    {
        "$project": {
            "timestamp": {"$dateToString": {"date": "$payload.ts", "format": "%m-%d-%Y"}},
            "value": "$payload.val",
            "timestampOriginal": {"$toLong": "$payload.ts"},
        }
    },
    {
        "$group": {
            "_id": "$timestamp",
            "open": {"$first": "$value"},
            "close": {"$last": "$value"},
            "avg": {"$avg": "$value"},
            "high": {"$max": "$value"},
            "low": {"$min": "$value"},
            "sum": {"$sum": "$value"},
            "count": {"$sum": 1},
            "timestamp": {"$first": "$timestampOriginal"},
        }
    },
    {"$sort": {"timestamp": 1}},
]

The data is very similar, see screenshot below where I printed parts of both datasets.

datasets look similar

creyD
  • 1,972
  • 3
  • 26
  • 55

0 Answers0