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

Time:06-14

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?

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));

CodePudding user response:

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

  • Related