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

150
Views
Unique Property of MongoDB is not working with Mongoose Node.js

Unique Property of MongoDB is not working with Mongoose Node.js. Data is continuously inserting in database. You can find the image too. I am a very initial stage of learning MongoDB with node.js.

enter image description here

const express = require('express')
const app =  express()
const port = 3000
const mongoose = require('mongoose')

mongoose.connect('mongodb://127.0.0.1:27017/gofuel').then(con=>{
    console.log("Connected", con);
}).catch(err=>{
    console.log(err);})

app.listen(port,()=>{
    console.log(`App is listening on Port ${port}`);
})

app.get('/',(req, res)=>{
    run()
    res.json({
        status : "200"
    })
})

const Users = mongoose.Schema({
    name :{
        type: String,
        unique: true
    }
}) 

const UserModel = mongoose.model('users', Users)

async function run(){
    const user = await new UserModel({
        name : "ndf"
    })

await user.save().then(res=>{
        console.log("User Created", res);
    }).catch(err=>{
        console.log(err);
    })
}

about 4 years ago · Juan Pablo Isaza
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!