Open keijop opened 2 years ago
I also had this problem. I installed lower version(2.0.3) of mongoose-unique-validator
package and it works now.
"mongoose": "^6.0.12",
"mongoose-unique-validator": "^2.0.3"
It seems like PR to fix this issue was opened back in 2019 and it wasnt merged yet. https://github.com/blakehaswell/mongoose-unique-validator/pull/109/files
I just got this bug, it happens only after you create a second entity, for example you have a relationship between users and places, where a place belongs to only a user. Then it works if you only have one user in your db, but once you add a second user, the save(), starts failing showing the OP error.
User validation failed: _id: Error, expected
_idto be unique. Value:
619987e6ace886176b3c656b`
It worked after disabling mongoose-unique-validartor 3.0.0
I have same problem. @machy44 How u installed previous version? When I tried it with:
npm install mongoose-unique-validator@2.0.3
I got errors:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: project@1.0.0
npm ERR! Found: mongoose@6.0.13
npm ERR! node_modules/mongoose
npm ERR! mongoose@"^6.0.12" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer mongoose@"^5.2.1" from mongoose-unique-validator@2.0.3
npm ERR! node_modules/mongoose-unique-validator
npm ERR! mongoose-unique-validator@"2.0.3" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
I got errors:
Try npm install mongoose-unique-validator@2.0.3 --legacy-peer-deps Just like the error text are saying. :D
Sorry @jakuub33 didnt see your message before. I hope you tried as Tobias wrote and succeeded in a meantime.
I got errors:
Try npm install mongoose-unique-validator@2.0.3 --legacy-peer-deps Just like the error text are saying. :D
Also part8 - c - Database and user administration has same problem. This method solved the problem.
mongoose-unique-validator "3.0.0" has a bug. It throws validation error "Error, expected
_id
to be unique" when using _id as a reference in another collection. Chapter 4 C populate is affected by this behaviour and also the tasks that follow. https://github.com/blakehaswell/mongoose-unique-validator/issues/131