Problems with creating MongoDB credential

Describe the issue/error/question

I tried to create a MongoDB credential, using configuration type: Values
Putting all my connection parameters there and getting an error.

What is the error message (if any)?

Couldn’t connect with these settings
Database “AH” does not exist

Information on your n8n setup

  • n8n version: 0.199.0
  • Database you’re using (default: SQLite): Postgre
  • Running n8n with the execution process [own(default), main]: queue
  • Running n8n via [Docker, npm,, desktop app]: Docker

Need a bit more info.

  • What version of MongoDB?
  • Is your MongoDB behind a firewall?
  • Did you test using the mongodb client from the same host?
  • Did you test these credentials from anywhere else?
  • Does the database “AH” in fact exist, and is it actually upper-case? (it’s case-sensitive I believe)

Mongo DB Version 6.0.2
I am inside a docker network, and it is connecting to the database, because before connecting it was throwing a different error.
MongoDB does not use SQL, and if the database does not exist, it is supposed to create it automatically. But I went in and created the database, no difference though.

Hey @Martin_Neumann,

I am not a MongoDB user but automatically creating a database sounds a bit odd to me, I also can’t find a reference to this in the MongoDB documentation, do you happen to have a link to it?

When you did make the database did you get a different error message? I would expect it to not say the database doesn’t exist so it may be handy to know what the new error message is.

Yes, MongoDB creates databases and collections automatically, the first time you reference them. After I referenced the database successfully in the MongoDB terminal, the error message still remains to be the same.

Actually, I found out now that I was referencing the database in the terminal, but it is getting created only after the first write operation. After writing a record, I could actually access the database in n8n. Seems that resolved the problem. Maybe it would be good to put that detail into the documentation.

Hey @Martin_Neumann,

Which bit of information? I know MongoDB will create documents / collections as you call them but I still can’t see anything to say it will make the actual database in the official documentation.

If you can share the MongoDB docs that says this is the case we can include it and put a link in our docs.

MongoDB does not use SQL

Sorry that was a total typo on my part. It was late last night when I responded.

Glad you got it sorted

The way you start out on a fresh MongoDB is the following:
use databasename
db.collectionname.insertOne({JSonkey: Jsonvalue })
After doing that in the Mongo Shell, the database is created.
Check for example here in the doc:

Ah that is perfect @Martin_Neumann and has what I couldn’t find in the connection.

You do not need to create the database before you switch. MongoDB creates the database when you first store data in that database (such as create the first collection in the database).

I will set up a MongoDB instance and have a play, I suspect the connection test would fail but looking at that if you try a write action it should make it so it could be a bug in the MongoDB nodejs package.

It may be that when putting the database into the connection string, that the database needs to exist. I dont know the details about that. Maybe worthwhile making some tests around that.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.