Relative Content

Tag Archive for pythonmongodbpymongobson

Unable to push data into a nested BSON object in Mongodb using pymongo

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 […]