sails: Sails v1.0 & sails-mongo: Can't create a document with custom id value
From @Josebaseba on February 28, 2017 3:53
sails: v1.0.0-27 sails-mongo: 1.0.0-4
I can’t create a document with a custom id like: '58959f6f6e6d1b620acc7a00', it always gets overwritten by another “random” ID. I tried in all the possible ways but I couldn’t.
Plus, if you have your models migration option set to 'alter' the id of all the objects keep changing, so if you have a model with an association to that other document you lose it.
It took me like an hour to realize about what was happening 😃
Copied from original issue: balderdashy/sails-mongo#456
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 19 (8 by maintainers)
@algope This should be all set with the latest beta of Waterline and sails-mongo. The easiest way to get it in your project is:
Then you should be able to set
dontUseObjectIds: truein your model, and set up theidattribute however you want, e.g.:Give that a whirl and let us know if it works for you!
Indeed. Thanks a lot 😃
You need to use a real mongo id, something like this:
"5af2d22aa7cec4083c4c4c4d"