Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MongoDB ObjectID() -> Can you create a 'simplified' one?

I’m trying to find a way to create a document key [not primary key, but still unique] that is user friendly (like 6 digits/letters long or something). I’ve looked at using a SequenceField [mongoengine], but I’ve also read about its drawbacks and the preference for ObjectIDs instead.

Basically, I’m trying to achieve something like this MongoDB blogpost, where I can auto_version documents, but ideally also have a user friendly key-field that allows me to pull up all versions of the document at once.

I hope that makes sense… I’m new to MongoDB.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thx!

>Solution :

You can self generate a uuid to be used as a unique identifier (e.g. doc_id) for versioning, and keep ObjectID as a _id.

Example packages

Nodejs – https://www.npmjs.com/package/uuid

Golang – https://github.com/google/uuid

Python – https://docs.python.org/3/library/uuid.html

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading