Im using django and mongoDB connected by Pymongo.
And i made a collection of users that inside each user there are details, and a calender when the user first register the calendar is an empty array(could be changed if needed), in the calendar would be a list of years, inside every year a list of months, inside every month would be a list of days, and in every day a list of events.
And i need that when a user wants to add an event to a specific date it would add it to the correct path meaning if the specified year allready exists it would insert the event in it and so on for the month and day.
But if the year isnt exist yet it would create the needed path.
Every thing i tried or not updating at all, or adding duplicates and ignores the allready created data.
Does someone has a solution for that case?
And if thats not the correct architecture for a mongo database feel free to improve it.
Thank you very much.
For example i tried
users = db[“users”]
users.update_one({“_id”: user}, {“$addToSet”: {“year”: year, “months”: [{“month”: month, “days”: [{“day”: day, “events”: [new_event]}]}]}}}, upsert=True)
But it adds a new year every time i add an event even if the year exists
Nevo Lag is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.