feathersjs-ecosystem / feathers-mongoose

Easily create a Mongoose Service for Feathersjs.
MIT License
189 stars 96 forks source link

Passing `validateBeforeSave:false` via `params.mongoose` does not work. #257

Open flight9 opened 6 years ago

flight9 commented 6 years ago

Steps to reproduce

There is a Users Schema in my project with a password field which is set to 'required: true'. Now I have to create a list of users using data from an excel file which does not offer any password value (because the boss hopes no password can be touched by client users). So I have to skip the mongoose validation when I call feathers service to create a user. I found in docs here that params.mongoose will help (see https://github.com/feathersjs-ecosystem/feathers-mongoose#paramsmongoose). I use the code:

let createParams = {
  user: params.user,
  mongoose: { validateBeforeSave: false }
};
for (let k in newDocs) {
  let doc = newDocs[k];
  console.log('newDoc before:', JSON.stringify(doc, null, 2));
  let ok = await service.create(doc, createParams);
}

but it still validates the doc and throw an error Path password is required.

Expected behavior

Passing validateBeforeSave:false via params.mongoose should skip mongoose validating before creating.

Actual behavior

Passing validateBeforeSave:false via params.mongoose does not work.

System configuration

Version node.js: 8.9.3 mongoose: 5.2.3 MongoDB: 3.6.1 feathers-mongoose: 6.1.2

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Apologies if the issue could not be resolved. FeathersJS ecosystem modules are community maintained so there may be a chance that there isn't anybody available to address the issue at the moment. For other ways to get help see here.

flight9 commented 5 years ago

any idea?