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.
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.
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.
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.