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

145
Vistas
Sails v1.x stores null and empty values to mongodb database

Sails v1.x stores empty properties in database mongoDb, when POST api call is made with request having few properties only from actual model defined in sails model, such properties which are not available in request is saved with empty values in database collection which was not the case in sails v0.12 Since I have migrated project from sails v0.12 to sails v1.x, I am facing this issue which is leading to code breakage on api response.

I am using JOI library to validate the request properties and below is the data that is being sent to <ModelName>.create(topic).fetch()

topic = {
  published: false,
  closed: false,
  name: 'Topic G -01',
  communityId: '57d640b3-cda6-4703-8080-2ef604de2086',
  activityId: '23ef04f4-699d-47c7-94ad-3fb5b1c18889',
  createdByUserId: '3cc6dddd-9425-42b8-83fc-4ba3f068128d',
  board: '5f7cc128c2380d00172225ee'
} 

Data getting saved in database collection as below:

{
  _id: ObjectId("61c9d4ec5ceca05c4b0016cb"),
  published: false,
  closed: false,
  name: 'Topic G -01',
  communityId: '57d640b3-cda6-4703-8080-2ef604de2086',
  activityId: '23ef04f4-699d-47c7-94ad-3fb5b1c18889',
  createdByUserId: '3cc6dddd-9425-42b8-83fc-4ba3f068128d',
  board: '5f7cc128c2380d00172225ee',
  createdAt: '2021-12-28T16:11:07.229Z',
  updatedAt: '2021-12-28T16:11:07.229Z',
  description: '',
  content: null,
  official: false,
  locked: false,
  singleResponses: false,
  responseTierLimit: 0,
  deleteOwnResponses: false,
  showQuantResults: false,
  probeQuantResponse: false,
  ratingSystem: '',
  responseVisibility: '',
  allowParticipantQuestions: false,
  qIndexVisibility: false,
  disablePostReplies: false,
  publishedAt: null,
  questionIds: null,
  updatedByUserId: '',
  includedRoles: null,
}

However in sails v0.12, on the contrary it used to store as below:

{
_id: ObjectId("61c9d4ec5ceca05c4b0016cb"),
  published: false,
  closed: false,
  name: 'Topic G -01',
  communityId: '57d640b3-cda6-4703-8080-2ef604de2086',
  activityId: '23ef04f4-699d-47c7-94ad-3fb5b1c18889',
  createdByUserId: '3cc6dddd-9425-42b8-83fc-4ba3f068128d',
  board: '5f7cc128c2380d00172225ee',
  createdAt: '2021-12-28T16:11:07.229Z',
  updatedAt: '2021-12-28T16:11:07.229Z',
}
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