Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

My Nodejs code point to Test database instead of my actual database in Mongo db

My insert command is working properly, from Nodejs to Mongodb . But instead of inserting into my database "School" in my mongodb cluster, it inserts into "test". How to point the insertion to my database.

My connection url format is like below

DATABASE_URL =mongodb+srv://myusername:mypassword@cluster0.<7 letter word>.mongodb.net/?retryWrites=true&w=majority

Is there anything i need to change?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

My database connection code

//database
const mongoose = require("mongoose");
mongoose
  .connect(process.env.DATABASE_URL, { useNewURLParser: true })
  .then(() => {
    console.log("Database connected");
  })
  .catch((err) => console.log(err));

>Solution :

You are connecting to the default db on the cluster, which is your case is probably test. You should specify the db you want to connect to
your-connection-string/[defaultauthdb][?options]]
Read more here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading