Connect to Mongo db using node js as custom actions


I would like to know how to connect and retrieve data from mongo db using node js as custom actions where the api is Graphql

Hi @somit1234,

You can write your own action server in node js. In your own action server, you have full flexibility to work with a mongo db or use a Graphql.

For more details, see here.

That section of the docs links to the Action Server REST API you need to adhere to for Rasa to be able to tell your server what action to run.

HI Arjaan,

I have written a simply node js code to connect to db. I started the action using rasa run actions --actions actions.js command but got error as “Failed to register package ‘actions.js’”

below is the code of actions.js

var MongoClient = require(‘mongodb’).MongoClient; MongoClient.connect(“mongodb://localhost:27017/database”, function (err, db) {

 if(err) throw err;


can you please provide a small example/syntax of node js custom actions

Hi @somit1234,

When you use the command rasa run actions , you are using the Rasa Python SDK. With that action server you can only use python functions for your actions.

If you want to use a node.js based action server, you need to write the server yourself. This blog post describes a specific example how to go about that.