strapi / strapi-starter-next-ecommerce

Strapi Starter Next.js E-commerce
strapi-starter-next-ecommerce.strapijs.vercel.app
MIT License
216 stars 73 forks source link

Issue on bootstrapping with MongoDb #18

Open tnovau opened 3 years ago

tnovau commented 3 years ago

When I load this starter with MongoDb it's failing on bootstrapping:

Error: product validation failed: _id: Cast to ObjectId failed for value "1" at path "_id"
    at ValidationError.inspect (/home/tomas/repos/handmade.amar/ecommerce/backend/node_modules/mongoose/lib/error/validation.js:47:26)
    at formatValue (internal/util/inspect.js:736:19)
    at inspect (internal/util/inspect.js:310:10)
    at formatWithOptionsInternal (internal/util/inspect.js:1969:40)
    at formatWithOptions (internal/util/inspect.js:1851:10)
    at console.value (internal/console/constructor.js:323:14)
    at console.log (internal/console/constructor.js:358:61)
    at /home/tomas/repos/handmade.amar/ecommerce/backend/config/functions/bootstrap.js:109:15
    at processTicksAndRejections (internal/process/task_queues.js:95:5) {
  errors: {
    _id: CastError: Cast to ObjectId failed for value "1" at path "_id"
        at ObjectId.cast (/home/tomas/repos/handmade.amar/ecommerce/backend/node_modules/mongoose/lib/schema/objectid.js:269:11)
        at ObjectId.SchemaType.applySetters (/home/tomas/repos/handmade.amar/ecommerce/backend/node_modules/mongoose/lib/schematype.js:1075:12)
        at model.$set (/home/tomas/repos/handmade.amar/ecommerce/backend/node_modules/mongoose/lib/document.js:1250:20)
        at model._handleIndex (/home/tomas/repos/handmade.amar/ecommerce/backend/node_modules/mongoose/lib/document.js:1019:14)
        at model.$set (/home/tomas/repos/handmade.amar/ecommerce/backend/node_modules/mongoose/lib/document.js:960:22)
        at model.Document (/home/tomas/repos/handmade.amar/ecommerce/backend/node_modules/mongoose/lib/document.js:150:12)
        at model.Model (/home/tomas/repos/handmade.amar/ecommerce/backend/node_modules/mongoose/lib/model.js:106:12)
        at new model (/home/tomas/repos/handmade.amar/ecommerce/backend/node_modules/mongoose/lib/model.js:4686:15)
        at /home/tomas/repos/handmade.amar/ecommerce/backend/node_modules/mongoose/lib/model.js:3052:22
        at /home/tomas/repos/handmade.amar/ecommerce/backend/node_modules/mongoose/lib/model.js:3088:7
        at Array.forEach (<anonymous>)
        at /home/tomas/repos/handmade.amar/ecommerce/backend/node_modules/mongoose/lib/model.js:3087:15
        at /home/tomas/repos/handmade.amar/ecommerce/backend/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:5
        at new Promise (<anonymous>)
        at promiseOrCallback (/home/tomas/repos/handmade.amar/ecommerce/backend/node_modules/mongoose/lib/helpers/promiseOrCallback.js:30:10)
        at Function.create (/home/tomas/repos/handmade.amar/ecommerce/backend/node_modules/mongoose/lib/model.js:3022:10) {
      stringValue: '"1"',
      messageFormat: undefined,
      kind: 'ObjectId',
      value: 1,
      path: '_id',
      reason: Error: Argument passed in must be a single String of 12 bytes or a string of 24 hex characters
          at new ObjectID (/home/tomas/repos/handmade.amar/ecommerce/backend/node_modules/bson/lib/bson/objectid.js:59:11)
          at castObjectId (/home/tomas/repos/handmade.amar/ecommerce/backend/node_modules/mongoose/lib/cast/objectid.js:25:12)
          at ObjectId.cast (/home/tomas/repos/handmade.amar/ecommerce/backend/node_modules/mongoose/lib/schema/objectid.js:267:12)
          at ObjectId.SchemaType.applySetters (/home/tomas/repos/handmade.amar/ecommerce/backend/node_modules/mongoose/lib/schematype.js:1075:12)
          at model.$set (/home/tomas/repos/handmade.amar/ecommerce/backend/node_modules/mongoose/lib/document.js:1250:20)
          at model._handleIndex (/home/tomas/repos/handmade.amar/ecommerce/backend/node_modules/mongoose/lib/document.js:1019:14)
          at model.$set (/home/tomas/repos/handmade.amar/ecommerce/backend/node_modules/mongoose/lib/document.js:960:22)
          at model.Document (/home/tomas/repos/handmade.amar/ecommerce/backend/node_modules/mongoose/lib/document.js:150:12)
          at model.Model (/home/tomas/repos/handmade.amar/ecommerce/backend/node_modules/mongoose/lib/model.js:106:12)
          at new model (/home/tomas/repos/handmade.amar/ecommerce/backend/node_modules/mongoose/lib/model.js:4686:15)
          at /home/tomas/repos/handmade.amar/ecommerce/backend/node_modules/mongoose/lib/model.js:3052:22
          at /home/tomas/repos/handmade.amar/ecommerce/backend/node_modules/mongoose/lib/model.js:3088:7
          at Array.forEach (<anonymous>)
          at /home/tomas/repos/handmade.amar/ecommerce/backend/node_modules/mongoose/lib/model.js:3087:15
          at /home/tomas/repos/handmade.amar/ecommerce/backend/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:5
          at new Promise (<anonymous>)
    }
  },
  _message: 'product validation failed'
}
tnovau commented 3 years ago

It's related to the id property. It's an string and mongoDb it's expecting an ObjectId.

Also I have changed the way the products are linked to categories.