# Issue with saving conversation into mongodb

**URL:** <https://forum.rasa.com/t/issue-with-saving-conversation-into-mongodb/2889>\
**Category:** Rasa Open Source\
**Created:** [November 22, 2018, 1:08pm UTC](https://forum.rasa.com/t/issue-with-saving-conversation-into-mongodb/2889 "2018-11-22T13:08:41Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![dhanya\_k\_s](https://avatars.discourse-cdn.com/v4/letter/d/5f8ce5/32.png) [@dhanya\_k\_s](https://forum.rasa.com/u/dhanya_k_s)\
**Post date:** [November 22, 2018, 1:08pm UTC](https://forum.rasa.com/t/issue-with-saving-conversation-into-mongodb/2889/1 "2018-11-22T13:08:41Z")

</div>

Hi,

I am trying to save the RASA conversations in mongodb. I have taken the restaurantbot example from rasa\_core and trying to save the conversation. Followed the instructions as mentioned in the documentation for mongo tracker store.

Changes made:

1. In bot.py to include MongoTrackerStore and changed the agent to include this tracker\_store.
2. In endpoints.yml added the following tracker store: tracker\_store: store\_type: mongod url: mongodb://localhost:27017 db: rasa

Observations: The new db(rasa) and collection (conversations) is getting created in mongodb. However the actual chat is not getting stored into the db. The collection is empty.

Please advice on what could be the issue. This is executed on a window machine.

Thank you.

---

<div class="post-metadata">

**Author:** ![souvikg10](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/souvikg10/32/93_2.png) [@souvikg10](https://forum.rasa.com/u/souvikg10)\
**Post date:** [November 22, 2018, 7:35pm UTC](https://forum.rasa.com/t/issue-with-saving-conversation-into-mongodb/2889/2 "2018-11-22T19:35:40Z")

</div>

I think the issue probably comes from the fact that you have a bot.py where you pass the tracker\_store as MongoTrackerStore but do you provide the connection parameters there?

unless you are using the rasa run.py script, the endpoints won’t be passed to the agent or you have to pass the endpoints yourself.

It is either you pass the tracker store directly with all the params to the Agent class using python or via the run.py script and endpoints.yml

in your case, the endpoints.yml is creating the collection but the agent you instantiated is not connecting to the right mongodb

---

<div class="post-metadata">

**Author:** ![dhanya\_k\_s](https://avatars.discourse-cdn.com/v4/letter/d/5f8ce5/32.png) [@dhanya\_k\_s](https://forum.rasa.com/u/dhanya_k_s)\
**Post date:** [November 23, 2018, 5:39am UTC](https://forum.rasa.com/t/issue-with-saving-conversation-into-mongodb/2889/3 "2018-11-23T05:39:01Z")

</div>

Hi Souvik,

Thank you for the reply.

This is the snapshot of the code in bot.py

```
domain = Domain.load('restaurant_domain.yml')

```

db = MongoTrackerStore( domain,host=‘mongodb://localhost:27017’, db=“rasa”, username=None, password=None, collection=“conversations”, event\_broker=None)

def train\_dialogue(domain\_file=“restaurant\_domain.yml”, model\_path=“models/dialogue”, training\_data\_file=“data/babi\_stories.md”): nlu\_interpreter = RasaNLUInterpreter(’./models/nlu/default/current/’) action\_endpoint = EndpointConfig(url=“[http://localhost:5055/webhook](http://localhost:5055/webhook)”)

```
agent = Agent(domain_file,
              policies=[MemoizationPolicy(max_history=3),
                        RestaurantPolicy()],
                            tracker_store=db,
              interpreter=nlu_interpreter,
              generator=None, action_endpoint=action_endpoint,
              fingerprint=None)

training_data = agent.load_data(training_data_file)
agent.train(
    training_data,batch_size=100, epochs=600,validation_split=0.2
)

agent.persist(model_path)
return agent

```

The command used to run rasa core:

python -m rasa\_core.run --nlu models/nlu/default/current --core models/dialogue --endpoints endpoints.yml --debug

So as per this the endpoints are being passed to the agent.

Do you see any issue with this?

Thank you.

---

<div class="post-metadata">

**Author:** ![souvikg10](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/souvikg10/32/93_2.png) [@souvikg10](https://forum.rasa.com/u/souvikg10)\
**Post date:** [November 23, 2018, 6:40am UTC](https://forum.rasa.com/t/issue-with-saving-conversation-into-mongodb/2889/4 "2018-11-23T06:40:25Z")

</div>

What does the log say? because if it can’t find the tracker store, you won’t have the states saved and the next prediction won’t be correct

---

<div class="post-metadata">

**Author:** ![dhanya\_k\_s](https://avatars.discourse-cdn.com/v4/letter/d/5f8ce5/32.png) [@dhanya\_k\_s](https://forum.rasa.com/u/dhanya_k_s)\
**Post date:** [November 23, 2018, 7:04am UTC](https://forum.rasa.com/t/issue-with-saving-conversation-into-mongodb/2889/5 "2018-11-23T07:04:01Z")

</div>

Hi Souvik,

There are no errors in the logs.

Below are the logs:

Bot loaded. Type a message and press enter (use '/stop' to exit): hi 2018-11-23 12:29:37 DEBUG rasa\_core.tracker\_store - Creating a new tracker for id 'default'. 2018-11-23 12:29:37 WARNING py.warnings - C:\Program Files\Python36\lib\site-packages\sklearn\preprocessing\label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size \> 0` to check that an array is not empty. if diff:

2018-11-23 12:29:37 DEBUG rasa\_core.processor - Received user message ‘hi’ with intent ‘{‘name’: ‘greet’, ‘confidence’: 0.9904502504823246}’ and entities ‘[]’ 2018-11-23 12:29:37 DEBUG rasa\_core.processor - Logged UserUtterance - tracker now has 2 events 2018-11-23 12:29:37 DEBUG rasa\_core.processor - Current slot values: cuisine: None info: None location: None matches: None people: None price: None 2018-11-23 12:29:37 DEBUG rasa\_core.policies.memoization - Current tracker state [None, {}, {‘intent\_greet’: 1.0, ‘prev\_action\_listen’: 1.0}] 2018-11-23 12:29:37 DEBUG rasa\_core.policies.memoization - There is a memorised next action ‘10’ 2018-11-23 12:29:37 DEBUG rasa\_core.policies.ensemble - Predicted next action using policy\_0\_MemoizationPolicy 2018-11-23 12:29:37 DEBUG rasa\_core.processor - Predicted next action ‘utter\_ask\_howcanhelp’ with prob 1.00. 2018-11-23 12:29:37 DEBUG rasa\_core.processor - Action ‘utter\_ask\_howcanhelp’ ended with events ‘[]’ 2018-11-23 12:29:37 DEBUG rasa\_core.processorhow can I help you? - Bot utterance ‘BotUttered(text: how can I help you?, data: { “elements”: null, “buttons”: null, “attachment”: null })’

2018-11-23 12:29:37 DEBUG rasa\_core.policies.memoization - Current tracker state [{}, {‘intent\_greet’: 1.0, ‘prev\_action\_listen’: 1.0}, {‘intent\_greet’: 1.0, ‘prev\_utter\_ask\_howcanhelp’: 1.0}] 2018-11-23 12:29:37 DEBUG rasa\_core.policies.memoization - There is a memorised next action ‘0’ 2018-11-23 12:29:37 DEBUG rasa\_core.policies.ensemble - Predicted next action using policy\_0\_MemoizationPolicy 2018-11-23 12:29:37 DEBUG rasa\_core.processor - Predicted next action ‘action\_listen’ with prob 1.00. 2018-11-23 12:29:37 DEBUG rasa\_core.processor - Action ‘action\_listen’ ended with events ‘[]’ 127.0.0.1 - - [2018-11-23 12:29:37] “POST /webhooks/rest/webhook?stream=true&token= HTTP/1.1” 200 187 0.288016 i want to search for a restaurant 2018-11-23 12:30:22 DEBUG rasa\_core.tracker\_store - Recreating tracker for id ‘default’ 2018-11-23 12:30:22 WARNING py.warnings - C:\Program Files\Python36\lib\site-packages\sklearn\preprocessing\label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty. if diff:

2018-11-23 12:30:22 DEBUG rasa\_core.processor - Received user message ‘i want to search for a restaurant’ with intent ‘{‘name’: ‘inform’, ‘confidence’: 0.9621039329920208}’ and entities ‘[]’ 2018-11-23 12:30:22 DEBUG rasa\_core.processor - Logged UserUtterance - tracker now has 6 events 2018-11-23 12:30:22 DEBUG rasa\_core.processor - Current slot values: cuisine: None info: None location: None matches: None people: None price: None 2018-11-23 12:30:22 DEBUG rasa\_core.policies.memoization - Current tracker state [{‘intent\_greet’: 1.0, ‘prev\_action\_listen’: 1.0}, {‘intent\_greet’: 1.0, ‘prev\_utter\_ask\_howcanhelp’: 1.0}, {‘intent\_inform’: 1.0, ‘prev\_action\_listen’: 1.0}] 2018-11-23 12:30:22 DEBUG rasa\_core.policies.memoization - There is no memorised next action 2018-11-23 12:30:22 DEBUG rasa\_core.policies.ensemble - Predicted next action using policy\_1\_RestaurantPolicy 2018-11-23 12:30:22 DEBUG rasa\_core.processor - Predicted next action ‘utter\_on\_it’ with prob 1.00. 2018-11-23 12:30:22 DEBUG rasa\_core.processor - Action ‘utter\_on\_it’ ended with events ‘[]’ 2018-11-23 12:30:22 I’m on itDEBUG rasa\_core.processor - Bot utterance ‘BotUttered(text: I’m on it, data: { “elements”: null, “buttons”: null, “attachment”: null })’ 2018-11-23 12:30:22 DEBUG rasa\_core.policies.memoization - Current tracker state [{‘intent\_greet’: 1.0, ‘prev\_utter\_ask\_howcanhelp’: 1.0}, {‘intent\_inform’: 1.0, ‘prev\_action\_listen’: 1.0}, {‘intent\_inform’: 1.0, ‘prev\_utter\_on\_it’: 1.0}] 2018-11-23 12:30:22 DEBUG rasa\_core.policies.memoization - There is no memorised next action 2018-11-23 12:30:22 DEBUG rasa\_core.policies.ensemble - Predicted next action using policy\_1\_RestaurantPolicy 2018-11-23 12:30:22 DEBUG rasa\_core.processor - Predicted next action ‘utter\_ask\_cuisine’ with prob 1.00. 2018-11-23 12:30:22 DEBUG rasa\_core.processor - Action ‘utter\_ask\_cuisine’ ended with events ‘[]’ 2018-11-23 12:30:22 DEBUG rasa\_core.processor - Bot utterance ‘BotUttered(text: what kind of cuisine would you like?, data: { “elements”: null, “buttons”: null, “attachment”: null })’ 2018-11-23 12:30:22 DEBUG rasa\_core.policies.memoization - Current tracker state [{‘intent\_inform’: 1.0, ‘prev\_action\_listen’: 1.0}, {‘intent\_inform’: 1.0, ‘prev\_utter\_on\_it’: 1.0}, {‘intent\_inform’: 1.0, ‘prev\_utter\_ask\_cuisine’: 1.0}] 2018-11-23 12:30:22 DEBUG rasa\_core.policies.memoization - There is no memorised next action 2018-11-23 12:30:22 DEBUG rasa\_core.policies.ensemble - Predicted next action using policy\_1\_RestaurantPolicy 2018-11-23 12:30:22 DEBUG rasa\_core.processor - Predicted next action ‘utter\_ask\_cuisine’ with prob 0.99. 2018-11-23 12:30:22 DEBUG rasa\_core.processor - Action ‘utter\_ask\_cuisine’ ended with events ‘[]’ 2018-11-23 12:30:22 DEBUG rasa\_core.processor - Bot utterance ‘BotUttered(text: what kind of cuisine would you like?, data: { “elements”: null, “buttons”: null, “attachment”: null })’ 2018-11-23 12:30:22 DEBUG rasa\_core.policies.memoization - Current tracker state [{‘intent\_inform’: 1.0, ‘prev\_utter\_on\_it’: 1.0}, {‘intent\_inform’: 1.0, ‘prev\_utter\_ask\_cuisine’: 1.0}, {‘intent\_inform’: 1.0, ‘prev\_utter\_ask\_cuisine’: 1.0}] what kind of cuisine would you like? what kind of cuisine would you like? 2018-11-23 12:30:22 DEBUG rasa\_core.policies.memoization - There is no memorised next action 2018-11-23 12:30:22 DEBUG rasa\_core.policies.ensemble - Predicted next action using policy\_1\_RestaurantPolicy 2018-11-23 12:30:22 DEBUG rasa\_core.processor - Predicted next action ‘utter\_ask\_cuisine’ with prob 0.96. 2018-11-23 12:30:22 DEBUG rasa\_core.processor - Action ‘utter\_ask\_cuisine’ ended with events ‘[]’ 2018-11-23 12:30:22 what kind of cuisine would you like?DEBUG rasa\_core.processor - Bot utterance ‘BotUttered(text: what kind of cuisine would you like?, data: { “elements”: null, “buttons”: null, “attachment”: null })’ 2018-11-23 12:30:22 DEBUG rasa\_core.policies.memoization - Current tracker state [{‘intent\_inform’: 1.0, ‘prev\_utter\_ask\_cuisine’: 1.0}, {‘intent\_inform’: 1.0, ‘prev\_utter\_ask\_cuisine’: 1.0}, {‘intent\_inform’: 1.0, ‘prev\_utter\_ask\_cuisine’: 1.0}] 2018-11-23 12:30:22 DEBUG rasa\_core.policies.memoization - There is no memorised next action 2018-11-23 12:30:22 DEBUG rasa\_core.policies.ensemble - Predicted next action using policy\_1\_RestaurantPolicy 2018-11-23 12:30:22 DEBUG rasa\_core.processor - Predicted next action ‘action\_listen’ with prob 0.86. 2018-11-23 12:30:22 DEBUG rasa\_core.processor - Action ‘action\_listen’ ended with events ‘[]’ 127.0.0.1 - - [2018-11-23 12:30:22] “POST /webhooks/rest/webhook?stream=true&token= HTTP/1.1” 200 423 0.116007

---

<div class="post-metadata">

**Author:** ![dhanya\_k\_s](https://avatars.discourse-cdn.com/v4/letter/d/5f8ce5/32.png) [@dhanya\_k\_s](https://forum.rasa.com/u/dhanya_k_s)\
**Post date:** [November 23, 2018, 7:05am UTC](https://forum.rasa.com/t/issue-with-saving-conversation-into-mongodb/2889/6 "2018-11-23T07:05:11Z")

</div>

The prediction seems to be correct. But none of the inputs are saved in db

---

<div class="post-metadata">

**Author:** ![souvikg10](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/souvikg10/32/93_2.png) [@souvikg10](https://forum.rasa.com/u/souvikg10)\
**Post date:** [November 23, 2018, 3:32pm UTC](https://forum.rasa.com/t/issue-with-saving-conversation-into-mongodb/2889/7 "2018-11-23T15:32:39Z")

</div>

Use the tracker API to retrieve values and check if the states are persisted if you restart the server

If you receive the old states then the tracker is stored in external tracker otherwise it is going to InMemory tracker

If it is the above case then you might be looking in a wrong collection or something

---

<div class="post-metadata">

**Author:** ![dhanya\_k\_s](https://avatars.discourse-cdn.com/v4/letter/d/5f8ce5/32.png) [@dhanya\_k\_s](https://forum.rasa.com/u/dhanya_k_s)\
**Post date:** [November 26, 2018, 5:20am UTC](https://forum.rasa.com/t/issue-with-saving-conversation-into-mongodb/2889/8 "2018-11-26T05:20:46Z")

</div>

Yeah. The mongodb database is empty. The states are getting saved in memory. After restart the conversations get reset. If there something to be done to switch to mongodb. Any sample code available to make this work?

---

<div class="post-metadata">

**Author:** ![souvikg10](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/souvikg10/32/93_2.png) [@souvikg10](https://forum.rasa.com/u/souvikg10)\
**Post date:** [November 26, 2018, 10:01am UTC](https://forum.rasa.com/t/issue-with-saving-conversation-into-mongodb/2889/9 "2018-11-26T10:01:54Z")

</div>

you don’t need to pass the tracker\_store for training the model.

Can you provide the format of your endpoints.yml, what parameters did you send for Mongodb

---

<div class="post-metadata">

**Author:** ![dhanya\_k\_s](https://avatars.discourse-cdn.com/v4/letter/d/5f8ce5/32.png) [@dhanya\_k\_s](https://forum.rasa.com/u/dhanya_k_s)\
**Post date:** [November 26, 2018, 10:17am UTC](https://forum.rasa.com/t/issue-with-saving-conversation-into-mongodb/2889/10 "2018-11-26T10:17:28Z")

</div>

Got this working now. Upgraded to the latest version of rasa\_nlu and rasa\_core.

Thanks for all the help, Souvik.

---

<div class="post-metadata">

**Author:** ![ihtisham0331](https://avatars.discourse-cdn.com/v4/letter/i/aeb1de/32.png) [@ihtisham0331](https://forum.rasa.com/u/ihtisham0331)\
**Post date:** [November 19, 2019, 2:17pm UTC](https://forum.rasa.com/t/issue-with-saving-conversation-into-mongodb/2889/11 "2019-11-19T14:17:36Z")

</div>

Continuing the discussion from [Issue with saving conversation into mongodb](http://forum.rasa.com/t/issue-with-saving-conversation-into-mongodb/2889/10):

please share your rasa core and nlu versions
