9

I plan to write a script to alter mongodb tables and fields based on this source: https://docs.mongodb.com/manual/tutorial/write-scripts-for-the-mongo-shell/

I plan to generate a UUID and put in a new field to be added to the altered tables, I found this reference on how to generate a BSON UUID object but there's a need for me to specify a 32-byte hexadecimal string to convert to the UUID BSON subtype. Ideally I'm looking for a mongodb equivalent to this which it auto generates UUID v1 by creating a random hash itself without the need of a 32-byte hexadecimal input. How is this done? I plan to create a script on this which mongodb will execute.

The Bassman
  • 2,241
  • 5
  • 26
  • 38

2 Answers2

2

Since I think there's no direct mongodb solution, I used this instead: Create GUID / UUID in JavaScript?, there's a fiddle which is fit for my needs.

Community
  • 1
  • 1
The Bassman
  • 2,241
  • 5
  • 26
  • 38
0

In javascript you can use this bson-objectid library

https://www.npmjs.com/package/bson-objectid

Yada
  • 30,349
  • 24
  • 103
  • 144