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

121
Vistas
Problem with mongoose schema and model typing

I want to use id, model and other fields. But I can't because reserved fields are substituted at the output, which are not described anywhere. That is, I have to guess that these fields cannot be used. How can I fix this situation? The example is copied from the official site, I just added a couple of fields.

I tried to use: interface with Document(official documentation not recommended to use),

import { Vehicle } from '~/shared/typings/vehicle'

import { Schema, model, connect } from 'mongoose'

type IUser = {
  id: string
  name: string
  model: string
  email: string
  avatar?: string
}

// 2. Create a Schema corresponding to the document interface.
const userSchema = new Schema<IUser>({
  id: { type: String, required: true },
  name: { type: String, required: true },
  model: { type: String, required: true },
  email: { type: String, required: true },
  avatar: String,
})

// 3. Create a Model.
const User = model<IUser>('User', userSchema)
const foo = await User.find()
foo.map((e) => e.id)

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