So I've been struggling with this problem for a while now and this is my last resort.
I need to be able to access and update a specific element in an array. I don't know the index in advance.
def SetTask(self, taskIndex, taskInfo):
todo = self.client.db.todo.update_one(
{"_id":self.user["Info"]["todo"]},
{
"$set":{
"tasks":to_dict(taskInfo)
}
}
)
I don't know how to access the element so any help would be appreciated.
A little help with how I've structured my database:
I have 2 different collections, one storing the user information and the other storing the to do lists for each user. Separated in case the document size limit becomes a problem later on as originally, it was going to be a sub document of the user document.
What I am basically doing here is finding the to do document that corresponds with the user, then trying to update the element at the index given as a parameter.
{
"_id": {
"$oid": "616865fae96df36467a89629"
},
"tasks": [
{
"basicInfo": "Basic",
"furtherInfo": "Further",
"dateDue": {
"$date": "2021-10-14T17:25:27.831Z"
},
"event": "event1",
"completed": false
},
{
"basicInfo": "Basic",
"furtherInfo": "Further",
"dateDue": {
"$date": "2021-10-14T17:29:18.901Z"
},
"event": "event2",
"completed": false
}
]
}