使用JSON填充MongoDB收集并为主键生成UUID,而不是使用ObjectID

发布于 2025-02-02 21:58:25 字数 635 浏览 2 评论 0原文

我一直在使用MongoDB指南针使用两种方法来填充MongoDB收集,并

使用命令的蒙古Shell:

mongoimport -jsonarray -jsonarray -authenticationDatabase admin -Username&username&username< username> gt; - password<密码> -c<收集名称> -d<数据库名称> drop-文件 - file<

,并在集合视图中通过Compass Interface GUI导入数据。

有没有办法设置主键_id在使用JSON文件填充集合时生成UUID而不是ObjectID?

使用uuids而不是objectids在mongodb中是关于可能性的讨论,是一种讨论使用UUID而不是ObjectIds的优点和缺点,但它没有讨论如何将主键设置为UUID而不是ObjectID,尤其是在使用JSON数据填充数据库时。

I have been populating MongoDB collections with JSON data via MongoDB Compass using two methods:

Through the mongosh shell with the command:

mongoimport --jsonArray --authenticationDatabase admin --username <username> --password <password> -c <collection name> -d <database name> drop --file <filename>

and by importing the data through the Compass interface GUI when in the collection view.

Is there a way to set the primary key _id to generate a UUID instead of the ObjectID when populating the collection with a JSON file?

Using UUIDs instead of ObjectIDs in MongoDB is a discussion of the possibilities, pros, and cons of using UUIDs instead of ObjectIDs, but it doesn't discuss how to set the primary key to be a UUID instead of ObjectID, particularly when populating the database with JSON data.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文