Chcę tą linijką kodu
const company = new Company({companyName: companyname, workersAmount: {max: workerslimit}});
nadpisać wartość max dla workers amount w zależności ile będzie wynosiła zmienna workerslimit.
Niestety po wywołaniu komendy z wartością 10 (co z kolei sprawdza warunek)
else if (workerslimit % 5 == 0)
pojawia się błąd
2024-02-25T14:15:01.322064+00:00 app[web.1]: /app/node_modules/mongoose/lib/document.js:3201
2024-02-25T14:15:01.322093+00:00 app[web.1]: this.$__.validationError = new ValidationError(this);
2024-02-25T14:15:01.322093+00:00 app[web.1]: ^
2024-02-25T14:15:01.322094+00:00 app[web.1]:
2024-02-25T14:15:01.322097+00:00 app[web.1]: ValidationError: Company validation failed: workersAmount: Cast to Number failed for value "{ max: '10' }" (type Object) at path "workersAmount"
2024-02-25T14:15:01.322098+00:00 app[web.1]: at Document.invalidate (/app/node_modules/mongoose/lib/document.js:3201:32)
2024-02-25T14:15:01.322098+00:00 app[web.1]: at model.$set (/app/node_modules/mongoose/lib/document.js:1460:12)
2024-02-25T14:15:01.322099+00:00 app[web.1]: at model.$set (/app/node_modules/mongoose/lib/document.js:1115:16)
2024-02-25T14:15:01.322099+00:00 app[web.1]: at model.Document (/app/node_modules/mongoose/lib/document.js:166:12)
2024-02-25T14:15:01.322099+00:00 app[web.1]: at model.Model (/app/node_modules/mongoose/lib/model.js:131:12)
2024-02-25T14:15:01.322100+00:00 app[web.1]: at new model (/app/node_modules/mongoose/lib/model.js:4700:15)
2024-02-25T14:15:01.322100+00:00 app[web.1]: at Client.<anonymous> (/app/src/bot.js:72:37)
2024-02-25T14:15:01.322101+00:00 app[web.1]: at Client.emit (node:events:518:28)
2024-02-25T14:15:01.322101+00:00 app[web.1]: at MessageCreateAction.handle (/app/node_modules/discord.js/src/client/actions/MessageCreate.js:28:14)
2024-02-25T14:15:01.322102+00:00 app[web.1]: at module.exports [as MESSAGE_CREATE] (/app/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32) {
2024-02-25T14:15:01.322102+00:00 app[web.1]: errors: {
2024-02-25T14:15:01.322103+00:00 app[web.1]: workersAmount: CastError: Cast to Number failed for value "{ max: '10' }" (type Object) at path "workersAmount"
2024-02-25T14:15:01.322103+00:00 app[web.1]: at SchemaNumber.cast (/app/node_modules/mongoose/lib/schema/number.js:380:11)
2024-02-25T14:15:01.322103+00:00 app[web.1]: at SchemaType.applySetters (/app/node_modules/mongoose/lib/schemaType.js:1221:12)
2024-02-25T14:15:01.322104+00:00 app[web.1]: at model.$set (/app/node_modules/mongoose/lib/document.js:1418:22)
2024-02-25T14:15:01.322104+00:00 app[web.1]: at model.$set (/app/node_modules/mongoose/lib/document.js:1115:16)
2024-02-25T14:15:01.322104+00:00 app[web.1]: at model.Document (/app/node_modules/mongoose/lib/document.js:166:12)
2024-02-25T14:15:01.322104+00:00 app[web.1]: at model.Model (/app/node_modules/mongoose/lib/model.js:131:12)
2024-02-25T14:15:01.322104+00:00 app[web.1]: at new model (/app/node_modules/mongoose/lib/model.js:4700:15)
2024-02-25T14:15:01.322104+00:00 app[web.1]: at Client.<anonymous> (/app/src/bot.js:72:37)
2024-02-25T14:15:01.322105+00:00 app[web.1]: at Client.emit (node:events:518:28)
2024-02-25T14:15:01.322105+00:00 app[web.1]: at MessageCreateAction.handle (/app/node_modules/discord.js/src/client/actions/MessageCreate.js:28:14) {
2024-02-25T14:15:01.322105+00:00 app[web.1]: stringValue: `"{ max: '10' }"`,
2024-02-25T14:15:01.322106+00:00 app[web.1]: messageFormat: undefined,
2024-02-25T14:15:01.322107+00:00 app[web.1]: kind: 'Number',
2024-02-25T14:15:01.322107+00:00 app[web.1]: value: { max: '10' },
2024-02-25T14:15:01.322107+00:00 app[web.1]: path: 'workersAmount',
2024-02-25T14:15:01.322107+00:00 app[web.1]: reason: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:
2024-02-25T14:15:01.322108+00:00 app[web.1]:
2024-02-25T14:15:01.322108+00:00 app[web.1]: assert.ok(!isNaN(val))
2024-02-25T14:15:01.322108+00:00 app[web.1]:
2024-02-25T14:15:01.322108+00:00 app[web.1]: at castNumber (/app/node_modules/mongoose/lib/cast/number.js:27:10)
2024-02-25T14:15:01.322108+00:00 app[web.1]: at SchemaNumber.cast (/app/node_modules/mongoose/lib/schema/number.js:378:12)
2024-02-25T14:15:01.322109+00:00 app[web.1]: at SchemaType.applySetters (/app/node_modules/mongoose/lib/schemaType.js:1221:12)
2024-02-25T14:15:01.322109+00:00 app[web.1]: at model.$set (/app/node_modules/mongoose/lib/document.js:1418:22)
2024-02-25T14:15:01.322109+00:00 app[web.1]: at model.$set (/app/node_modules/mongoose/lib/document.js:1115:16)
2024-02-25T14:15:01.322109+00:00 app[web.1]: at model.Document (/app/node_modules/mongoose/lib/document.js:166:12)
2024-02-25T14:15:01.322109+00:00 app[web.1]: at model.Model (/app/node_modules/mongoose/lib/model.js:131:12)
2024-02-25T14:15:01.322110+00:00 app[web.1]: at new model (/app/node_modules/mongoose/lib/model.js:4700:15)
2024-02-25T14:15:01.322110+00:00 app[web.1]: at Client.<anonymous> (/app/src/bot.js:72:37)
2024-02-25T14:15:01.322110+00:00 app[web.1]: at Client.emit (node:events:518:28) {
2024-02-25T14:15:01.322110+00:00 app[web.1]: generatedMessage: true,
2024-02-25T14:15:01.322110+00:00 app[web.1]: code: 'ERR_ASSERTION',
2024-02-25T14:15:01.322110+00:00 app[web.1]: actual: false,
2024-02-25T14:15:01.322111+00:00 app[web.1]: expected: true,
2024-02-25T14:15:01.322111+00:00 app[web.1]: operator: '=='
2024-02-25T14:15:01.322112+00:00 app[web.1]: },
2024-02-25T14:15:01.322112+00:00 app[web.1]: valueType: 'Object'
2024-02-25T14:15:01.322112+00:00 app[web.1]: }
2024-02-25T14:15:01.322112+00:00 app[web.1]: },
2024-02-25T14:15:01.322112+00:00 app[web.1]: _message: 'Company validation failed'
2024-02-25T14:15:01.322113+00:00 app[web.1]: }
którego nie rozumiem.
2024-02-25T14:15:01.322112+00:00 app[web.1]: valueType: 'Object'
Użyłem parseint dla zmiennej z liczbą 10
jak nadpisać wartość max wartością zmiennej?