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

151
Views
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
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!