Added support for $uuid#20
Conversation
|
Hi, what output do you want to create? Can you give an example? |
|
Hi Thomas. I was hoping for output in the JSON like this:
I'm pushing a customer to store UUID as binary in BSON rather than as a string, since I understand it takes ~ 50% the number of bytes to store. |
|
Hi @niccottrell, Your example is not valid JSON, you wouldn't be able to parse that with a JSON parser or use mongoimport to write it back into a database. MongoDB's extended JSON offers a "strict" and "shell" version. You describe the shell version. The strict version (which mgeneratejs and mongoimport/export use) needs to use the If you just want the UUID as a string, you can use the Chance.js |
|
Hi Thomas! Thanks - I wasn't aware that mongoimport didn't support the UUID("...") format. But it does support ObjectId("123...") in the JSON to import. Thanks for the $guid tip but I really wanted to create example JSON which, once imported, would be stored as the BSON UUID binary type since I'm looking at getting the filesize per document down as much as possible, but still have the mgenerated documents human-readable as UUID. |
|
mongoimport and extended json v2 now natively support uuid, can we add this support? |
|
Hi @mhelmstetter, just to confirm how this feature should work exactly: Does this look right? would produce the following output: According to https://www.mongodb.com/docs/manual/reference/mongodb-extended-json/#type-representations this is now the extended json format v2 for UUIDs, both relaxed and canonical form. Is that what you'd expect? |
This seems to work but creates ugly entries like
[{"$binary":"YTNhZTU0Y2ItZTczMS00YmEwLTk1ZmYtNDM5N2YxZmI5OWVk","$type":"4"}. Any idea how I can customize the JSON output?