最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to generate UUID using mongodb scripting - Stack Overflow

programmeradmin0浏览0评论

I plan to write a script to alter mongodb tables and fields based on this source: /

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.

I plan to write a script to alter mongodb tables and fields based on this source: https://docs.mongodb./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.

Share Improve this question asked Jun 21, 2016 at 4:13 The BassmanThe Bassman 2,3615 gold badges30 silver badges41 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 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.

In javascript you can use this bson-objectid library

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

发布评论

评论列表(0)

  1. 暂无评论