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

272
Views
How to update schema data in mongodb with mongoose and express

So I have a problem trying to work with mongodb. Firstly, I created a mongoose model like below which stores name.

const mongoose = require("mongoose");

const schema = new mongoose.Schema({
  name: {
    type: String
  },
 });
 
 mongoose.model("schema", schema);

And I posted a name. It looks like this in my mongodb compass.

{
  "_id": {
    "$oid": "628e0b35062e0d2e7fde17dc"
  },
  "name": "Bob",
}

Now I also want their age so I updated the model to this.

const mongoose = require("mongoose");

const schema = new mongoose.Schema({
  name: {
    type: String
  },
  age: {
    type: Number,
    default: 0
  }
 });
 
 mongoose.model("schema", schema);

The problem
The previous saved data at db doesnt have age property on it. I want previous registered name's age to be default to 0. New data will have the age property to them but not the previous data.

over 4 years ago · Santiago Trujillo
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!