I'm building an statistical system that when an user clicks a link, the python server sends date and time data to MongoDB. For example, if now is "2020-11-10, 11:41:20" then in MongoDB, there should be
{
_id: "1123",
time: {
2020: {
11: {
10: ["11:41:20"]
}
}
}
}
then, if another user clicks the link, say the time is "2020-11-13, 10:23:00", I want to push the data into already existing document above. The result should be
{
_id: "1123",
time: {
2020: {
11: {
10: ["11:41:20"],
13: ["10:23:00"]
}
}
}
}
What I've been doing is get all the data into a python object and manually insert new time data to the object, and update the whole document. is there any neat way to implement this?
Thanks in advance.
$objectToArray,$arrayToObjectand$reduceoperators. Apart from that you should never store date/time values as string, use properDateobjects.