def insertDataComments(self, company_profile_id, thread_id, commenter, comment_text):
DATABASE = "foretagsforum"
db = client[DATABASE]
collection = db.companies
try:
result = collection.update_one(
{"_id": company_profile_id, "threads._id": thread_id},
{"$push": {"threads.$.comments": {"commenter": commenter, "comment_text": comment_text}}}
)
return {"success": True, "matched_count": result.matched_count, "modified_count": result.modified_count}
except OperationFailure as e:
return {"error": f"Something went wrong: {e}"}
finally:
client.close()
def fetchUserThreads(self,username,items:int=1):
DATABASE = "threads-relations"
db = client[DATABASE]
thread = db.relations
try:
user_threads = thread.find({"username":username}).limit(items)
threads_list = list(user_threads)
return threads_list
except OperationFailure as e:
return {"Something went wrong":str(e)}
finally:
client.close()
So for some reason I am unable to push data into my nested bson object, for reference this is how the data is supposed to look like for example:
{
"_id": {
"$oid": "667f35a82435e055b88cdec4"
},
"company_name": "telenor-sverige-aktiebolag",
"org_number": "556421-0309",
"company_info": [],
"threads": [
{
"_id": {
"$oid": "667f35e141b617793ba93d72"
},
"username": "Kalle",
"thread_text": "This is the end of the long string.",
"tags": [
"string",
"long",
"word",
"repetit",
"repeat"
],
"timestamp": {
"$date": {
"$numberLong": "1719612897633"
}
},
"category": "jobb",
"comments": []
}
]
}
What am I missing, I’ve tried googling around for solutions and nesting bson objects in this was seems very rare, essentially I am trying to push data within data within data.