You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The latest Mongoose release (5.6.9) breaks my code, which worked fine with previous versions. I did not other changes beside the Mongoose update from 5.6.8 to 5.6.9.
In a Schema I have a string array field, defined this way:
roles: {type: [String],enum: VALID_ROLE_VALUES,get: functionrolesGetter(roles){// some logic that either returns "roles", or [...roles, "beta_user"]},},
This worked fine before the update, after the update I am getting this error upon the Schema creation:
`enum` can only be set on an array of strings, not undefined
45 | });
46 |
> 47 | const schema = new Schema({
| ^
48 | createdAt: {
49 | type: Date,
50 | default: () => Date.now(),
at SchemaArray.Object.<anonymous>.SchemaArray.enum (node_modules/mongoose/lib/schema/array.js:206:13)
at SchemaArray.SchemaType (node_modules/mongoose/lib/schematype.js:85:18)
at new SchemaArray (node_modules/mongoose/lib/schema/array.js:87:14)
at Schema.Object.<anonymous>.Schema.interpretAsType (node_modules/mongoose/lib/schema.js:865:12)
at Schema.Object.<anonymous>.Schema.path (node_modules/mongoose/lib/schema.js:606:27)
at Schema.add (node_modules/mongoose/lib/schema.js:444:12)
at new Schema (node_modules/mongoose/lib/schema.js:121:10)
at Object.<anonymous> (src/models/User.js:47:16)
at Object.<anonymous> (src/auth/methods/jwt.js:15:1)
If I try to comment out enum and get instructions, I get another error, when attempting to create corresponding documents:
ValidationError: User validation failed: roles: Cast to Array failed for value "[ 'shared_user' ]" at path "roles"
34 | await AnalysisOutput.deleteMany();
35 | await User.deleteMany();
> 36 | USERS.push(await User.create({
| ^
37 | _id: getMockMongoObjectId(),
38 | ethAddress: makeEthAddress(),
39 | roles: [ROLES.SHARED_USER],
at new ValidationError (node_modules/mongoose/lib/error/validation.js:30:11)
at model.Object.<anonymous>.Document.invalidate (node_modules/mongoose/lib/document.js:2317:32)
at model.$set (node_modules/mongoose/lib/document.js:1112:10)
at model._handleIndex (node_modules/mongoose/lib/document.js:877:14)
at model.$set (node_modules/mongoose/lib/document.js:821:22)
at model.Document (node_modules/mongoose/lib/document.js:124:12)
at model.Model (node_modules/mongoose/lib/model.js:92:12)
at new model (node_modules/mongoose/lib/model.js:4395:15)
at toExecute.push.callback (node_modules/mongoose/lib/model.js:3035:22)
at node_modules/async/internal/parallel.js:31:39
at eachOfArrayLike (node_modules/async/eachOf.js:65:9)
at Object.<anonymous>.exports.default (node_modules/async/eachOf.js:9:5)
at _parallel (node_modules/async/internal/parallel.js:30:5)
at parallelLimit (node_modules/async/parallel.js:88:26)
at utils.promiseOrCallback.cb (node_modules/mongoose/lib/model.js:3045:5)
at Promise (node_modules/mongoose/lib/utils.js:271:5)
at Object.promiseOrCallback (node_modules/mongoose/lib/utils.js:270:10)
at Function.create (node_modules/mongoose/lib/model.js:3006:16)
at Object.create (__tests__/functional/routes/analyses/issues.js:36:25)
The text was updated successfully, but these errors were encountered:
Regarding Jest and this issue, actually looking at your fix, and Node docs, I believe that Jest's require in this case behaves exactly according to the Node's module resolution algorithm, as described here: https://nodejs.org/dist/latest-v10.x/docs/api/modules.html#modules_all_together
If you do require('./') from a module /some/path/module.js, it will try load /some/path.js first and only if that fails it will eventually try /some/path/index.js.
You're looking at docs for node 0.10.x. I haven't tried this in every node version, but that is not how node 8.x works. If you don't believe me, try it yourself, maybe I'm missing something
The latest Mongoose release (5.6.9) breaks my code, which worked fine with previous versions. I did not other changes beside the Mongoose update from 5.6.8 to 5.6.9.
In a Schema I have a string array field, defined this way:
This worked fine before the update, after the update I am getting this error upon the Schema creation:
If I try to comment out
enum
andget
instructions, I get another error, when attempting to create corresponding documents:The text was updated successfully, but these errors were encountered: