You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
asyncfunctionappendChat(chatData: ChatContent){try{constdb=newDatastore({filename: "src/Db/UserChats.db",autoload: true,});constcondition={from: chatData.from,to: chatData.to};db.findOne(condition,(err: Error|null,userChat: any)=>{if(err){console.error("Error while searching for userChat:",err);}elseif(!userChat){// If userChat doesn't exist, create a new oneconstnewUserChat: TChat={from: chatData.from,to: chatData.to,ChatContent: [chatData],// Add other properties as needed};// Insert the new userChatdb.insert(newUserChat,(insertErr: Error|null,insertedUserChat: Chat)=>{if(insertErr){console.error("Error while inserting userChat:",insertErr);}else{console.log("New userChat created:",insertedUserChat);}});}else{console.log("UserChat already exists:",userChat);console.log(userChat._id);db.update({_id: userChat._id},{$push: {ChatContent: chatData}},{},(updateErr: Error|null,numUpdated: Chat)=>{if(updateErr){console.error("Error while updating userChat:",updateErr);}else{console.log("UserChat updated with new content:",numUpdated);}});}});}catch(err){console.error("Error hashing password:",err);}}
instead of updating the one that exists already. it creates a new object and saves it same _id
I tried to update a document which already exists
This is the function
instead of updating the one that exists already. it creates a new object and saves it same _id
Please help me solve it. Thankyou
The text was updated successfully, but these errors were encountered: