使用JSON填充MongoDB收集并为主键生成UUID,而不是使用ObjectID
我一直在使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论