uuid-mongodb
uuid-mongodb copied to clipboard
Add support for formatted UUIDs to the "from()" method.
The library has several formating options, which is nice, however it only understands one of them when you "parse" a string with the from()
method, which is weird.
Steps to reproduce:
const MUUID = require('uuid-mongodb');
const uuid1 = MUUID.v4();
console.log(uuid1); // Binary { ... }
const string = uuid1.toString('N');
console.log(string); // 9cea27b4d0e44781826ede1b6f378d6f
const uuid2 = MUUID.from(string); // Error: Invalid UUID
An optional parsing parameter like we have in the toString
method would make a lot of sense, e.g. MUUID.from(string, 'N');
this is a good idea. we should implement it.
would you be interested in submitting a PR?
This is needed. I have set my 'mode' on the schema creation to 'relaxed' and everywhere else I use MUUID
const mUUID = MUUID.mode('relaxed');
and in the schema:
_id: { type: 'object', value: { type: 'Buffer' }, default: () => mUUID.v4() },
except when stringified, the documents return the 'canonical' version of the string. I am unable to convert this canonical version to a uuid using MUUID.from("DEol4JenEeqVKusA+dzMMA==")
meaning I can't query the db...
@cdimascio does relaxed work with v4? What am I doing wrong here?
I'm looking for the same solution, how to parse the canonical version hJVV+w11SZqk+vK9BSCpeA==
or convert it to "relaxed" version?