• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

214
Views
MongoError: database names cannot contain the character '/'

I am using moongoose npm package. When I try to connect with mongodb I am getting this error. Here is my code.

const mongoose = require("mongoose");

mongoose.connect("mongodb://127.0.0.1/27017/task-manager-api", {
  useNewUrlParser: true,
  useCreateIndex: true,
});

const User = mongoose.model("User", {
  name: {
    type: String,
  },
  age: {
    type: Number,
  },
});

const me = new User({
  name: "Sushant",
  age: 17,
});

me.save()
  .then(() => {
    console.log(me);
  })
  .catch((error) => {
    console.log("Error Spotted");
  });

MongoError: database names cannot contain the character '/'

almost 3 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Port number should be added with colon instead of forward slash

const mongoose = require("mongoose");
    
    mongoose.connect("mongodb://127.0.0.1:27017/task-manager-api", {
      useNewUrlParser: true,
      useCreateIndex: true,
    });
    
    const User = mongoose.model("User", {
      name: {
        type: String,
      },
      age: {
        type: Number,
      },
    });
    
    const me = new User({
      name: "Sushant",
      age: 17,
    });
    
    me.save()
      .then(() => {
        console.log(me);
      })
      .catch((error) => {
        console.log("Error Spotted");
      });
almost 3 years ago · Juan Pablo Isaza Report

0

Your db URI contains a small typo mistake, as you wrote: mongodb://127.0.0.1/27017/task-manager-api

While it should be: mongodb://127.0.0.1:27017/task-manager-api

almost 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error