I am trying to design a chatbot that stores its chat history in mongo. For example, if a user in slack asks the question ‘I need help with vpn’ the bot will respond to that message with helpful information, it will then ask if it was helpful and they have buttons to select yes or no. I want mongo to be able to store that information in a collection for what the bot heard, time timestamp, and if the user selected the yes/no button. I am using model.findOneandUpdate() but that only seems to update the first item in the collection, not the current message/collection.
Maybe there is a better way to do what I am trying to do. I am using node.js to handle the bot.
Now the bot asks in the block if this information was helpful
I want the button answer (yes,no) to be added to the resolved part of the schema.
controller.on(‘block_actions’, async (bot, message) => {
if (message.text === 'No'){
await Msg.findOneAndUpdate({resolved:message.incoming_message.text});
console.log(message.incoming_message.channelData.actions[0].value)
await bot.replyEphemeral(message, 'If you need further assistance please reach out to us on chat at or call .');
} else if (message.text === 'Yes'){
await Msg.findOneAndUpdate({resolved:message.incoming_message.text});
console.log(message.incoming_message.channelData.actions[0].value)
await bot.replyEphemeral(message, 'Great! Is there anything else I can assist you with today?');
Not super familiar with mongoose but ai guess the save method should respond with a document id created (_id in MongoDB).
I know the insertOne return it. Potentially you can manage your own id field and populate it with identifier .
Then in your find and update provide the specific id as part of the filter (_id : <updated id> )
This way you can update a specific single document. Again updating multiple documents with same value require a different method than the methods with “one” in name…
Yes, I am looking to just update one collection/document so no need to update all of them. So you are saying to create a new object ID and then somehow update the response based on that objectID?