DEV Community

Cover image for Converting UUID to ObjectID from legacy mongo database
Gilson Doi Junior
Gilson Doi Junior

Posted on

Converting UUID to ObjectID from legacy mongo database

Recently I had to work on a project previously maintained by another company and that had adopted UUID as object ids in the collections. I don't know why the previous team choose to adopt UUID but for I had to integrate this database to a node module that we develop using mongoose and we had problems with the string representation of the UUID as follow:

client: "\u007fM6�u�K���2\u0006\u0002\u0001��"

Due to the short period to solve the problem, my team and I decided that would be faster and easier to migrate the existing ids from the database to default's ObjectID than having to analyse how the python UUID was generated with the following script:

The case here is not to question whether to use ObjectID or UUID ( more about this in mongodb blog ). Maybe I will work with node, mongodb and UUID in the future but for the moment we needed to solve this as fast as possible and the solution was to migrate the existing document ids.

Top comments (0)