如何在MongoDB Norm中设置hilo序列起始值?

发布于 2024-09-14 04:48:39 字数 129 浏览 1 评论 0原文

我通过规范驱动程序将许多现有值导入到我的 mongodb 中(包括“旧”id - 整数值)。现在我时不时会遇到重复的关键错误。

为了解决这个问题,我必须手动设置 hilo 序列的起始值。这怎么能做到呢?

提前致谢

i imported a lot of existing values into my mongodb via the norm driver (including the "old" id - integer value). Now i got duplicate key errors from time to time.

To solve this, i have to set the starting value for the hilo sequence manually. How can this be done?

Thanks in advance

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帅气称霸 2024-09-21 04:48:39

HiLo 密钥信息存储在 NormHiLoKey 集合中。您可以在 Mongo shell 中使用以下命令增加此集合中的值来更改生成的键的起始值:

db.NormHiLoKey.update({ _id: "nameOfCollection" }, { $inc: { ServerHi: 42 } })

注意

不要从蒙戈壳! ServerHi 存储为 64 位整数,无法在 shell 中表示。因此,如果您从 shell 设置该值,它将更改底层数据类型并破坏 NoRM 反序列化器。

如果您运行 db.NormHiLoKey.find() 命令,您可能会看到具有 floatApprox 属性的对象。这表明基础数据类型是 64 位整数。通过使用 $inc 运算符,您可以安全地修改该值,不会意外损坏任何东西。

The HiLo key information is stored in the NormHiLoKey collection. You can increment the value in this collection to change the starting value of the generated keys, using the following command in the Mongo shell:

db.NormHiLoKey.update({ _id: "nameOfCollection" }, { $inc: { ServerHi: 42 } })

CAUTION

Do not set the ServerHi value from the Mongo shell! The ServerHi is stored as a 64 bit integer, which cannot be represented in the shell. So if you set the value from the shell, it will change the underlying data type and break the NoRM deserializer.

If you run the db.NormHiLoKey.find() command, you'll likely see objects with floatApprox properties. This is an indication that the underlying data type is a 64 bit integer. By using the $inc operator you can safely modify the value, without accidentally breaking anything.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文