Objects are automatically stored in the 'test' database instead of the telegram bot's 'mydatabase' database

Good day, I am a newbie, I have two telegram bots written in node.js and I am using mongoose library. the first telegram bot performs admin function: adding users to MongoDB database. this bot has its own schema. the second telegram bot is for users. Here users enter data that was passed to the administrative bot to authorise themselves and access the functions of the user bot. the user bot refers to the schema of the administrative bot. all this is on a VPS Ubuntu Server.

I have this problem that when I add a new user, in MongoDB Compass the database is not called “mydatabase” but just "test" with collections.
I tried connecting via “mongodb+srv://user:password@myclaster.xo3epri.mongodb.net/mydatabase”, but I encountered that data saving is not going to the cluster, but to the old URI.
what am I doing wrong?

two bots are connected as follows:

    useNewUrlParser: true,
    useUnifiedTopology: true,
    useCreateIndex: true,

make sure you have stopped/killed all instances of your bots. If you use docker, or one like that, make sure to rebuild them.

It is possible one is still running in background and your changes are not applied because of that running instance.

I haven’t used docker, but the bots are running in the background via pm2. could this have any effect?

If you haven’t set its “watch” ability properly, then it surely affects.
PM2 - Watch & Restart (keymetrics.io)

Even when it is finely set up, your changes to your project might not be taken into account if there are optimizations. It is best to regularly restart the "watch"ing utility program, especially when your changes include key settings like this connection string.

For your problem, the actual reason might be something else but, again, first make sure to kill then restart all bots. Because, from your statements, bots use old connection string, which makes it a strong reason for my above suggested action.

oh my goodness that really worked. thanks so much for the tip!

1 Like