Closed
Description
Hi Team,
Thank you for developing Mongomock.
I've used mongomock to write a unit test code for my mongo fetch data pipeline.
My fetch data code has aggregate
and we use a couple of aggregate functions such as $week.
I got the error message below during the test.
AttributeError: 'dict' object has no attribute 'strftime'
from https://github.com/mongomock/mongomock/blob/4.0.0/mongomock/aggregate.py#L546
Here's my sample code.
import mongomock
import pandas as pd
from dateutil import parser
import datetime
def test_fetch_data(
):
client = mongomock.MongoClient()
client.my_db["test"].insert_many([{"name": "user1", "createdAt": parser.parse("2022-04-19T00:38:49.282Z")}])
# client.my_db["test"].insert_many([{"name": "user1", "createdAt": datetime.datetime(2022, 4, 19, 0, 38, 49, 282)}])
all = client.my_db["test"].find()
df = pd.DataFrame(all)
print(df)
aggregate = client.my_db["test"].aggregate(
[
{
"$match": {
"name": "user1"
}
},
{
"$set": {
"weekOfYear": {"$week": {"date": "$createdAt", "timezone": "America/Chicago"}},
}
}
]
)
df1 = pd.DataFrame(aggregate)
print(df1)
do you support $week
function in mongomock?
or
did I make some mistake in inserting date data?
Thank you.