Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

109
Views
How can I add an user at start in nodejs?

I want to create a user if I start my connection to localhost and mongoDB but I don´t know how to do it I tried so many things but don´t know how to get an user at start.

so my Schema looks this way:

const UserSchema = mongoose.Schema({
    userID: {
        type: String,
        required: true
    },
    userName: {
        type: String,
        required: true
    },
    password: {
        type: String,
        required: true
    },
    isAdministrator: {
        required: Boolean
    }
});

And my connection is this:

const dbURI = "mongodb://localhost:27017/test";
mongoose.connect(dbURI, {
    useNewUrlParser: true,
    useUnifiedTopology: true
})
const db = mongoose.connection;

db.on("error", (err)=>{console.error(err)});
db.once("open", () => { console.log ("Database started successfully")})
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use this user schema if you want to create a normal user-defined by default: false and if you want to create admin defined by default: true.

const UserSchema = mongoose.Schema({
  userID: {
    type: String,
    required: true,
  },
  userName: {
    type: String,
    required: true,
  },
  password: {
    type: String,
    required: true,
  },
  isAdministrator: {
    required: Boolean,
    default: false,
  },
});
about 4 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 Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!