I am looking for a way to $push an object to a nested array which the route keys come from variables.
{
"_id": {
"$oid": "5ce9964cd0e7df57eb0c8a99"
},
"history": {
"2019": {
"jan": {
"1": [],
"2": [],
"3": []
},
"feb": {
"1": [],
"2": [],
"3": []
}
}
}
}
def add_tx():
body = request.get_json()
users = mongo.db.date
users.find_one_and_update({
"username": session['username']
}, {
'$push': {
'history'[str(body['year'])][months[body['month']]][str(
body['day'])]: {body['title']: body['value']}
}
})
So the route in the "history" object comes from the body:
body['year'], body['month'], body['day']
and I want to append to the array an object with:
{body['title']: body['value']}