Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

279
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda