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

Time:10-07

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.

Thx!

CodePudding user response:

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

  • Related