Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to create Products - E11000 duplicate key error collection: test.products index: number_1 dup key: { number: null } - #955

Open
NicoEspositoARG opened this issue Feb 11, 2024 · 3 comments

Comments

@NicoEspositoARG
Copy link

Hi Team!
I just cloned the repo following the instructions, running locally using MongoDb from Atlas. I can create only one Product, when trying to create a second product I get the following error:

To Reproduce

  1. Create a product category successfully.
  2. Try to create a product from UI, fill the form and submit, got status code: 500

Endpoint: POST /api/product/create
Payload:

{
    "name": "Blue pen",
    "productCategory": "65c837697b9754e80cf11b9c",
    "price": 200
}

Response:

{
    "success": false,
    "result": null,
    "message": "E11000 duplicate key error collection: test.products index: number_1 dup key: { number: null }",
    "controller": "create",
    "error": {
        "index": 0,
        "code": 11000,
        "keyPattern": {
            "number": 1
        },
        "keyValue": {
            "number": null
        }
    }
}

Expected behavior
Other Models that don't have the number attribute are working as expected (can create or edit). But with Products, I was able to create only the first Document.

I'm on this commit:
4434edf (HEAD -> master, origin/master, origin/HEAD) Merge pull request #954 from idurar/dev

I have already tried dumping the DB, running reset script and then run setup again. Same result.

Thanks in advance.

@arman8808
Copy link

E11000 duplicate key error comes when we use unique property in mongodb

@salahlalami
Copy link
Member

@NicoEspositoARG in product Model remove unique : true from number field ,
then go to mongoldb (products collections ) and remove it (number_1) from index tabs

@NicoEspositoARG
Copy link
Author

@NicoEspositoARG in product Model remove unique : true from number field , then go to mongoldb (products collections ) and remove it (number_1) from index tabs

I did that and works as expected. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants