MongoDb中的全局自动递增字段

编程入门 行业动态 更新时间:2024-10-24 01:57:00
本文介绍了MongoDb中的全局自动递增字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否可以在集合中创建全局自动递增值?

Is there a way to create a globally auto-incrementing value in a collection?

Perforce具有变更列表#的概念,它可以成为无状态更新的强大功能.我在考虑相同类型的功能.

Perforce has the concept of a changelist# that can be a powerful feature for stateless updates. I am thinking of the same type of functionality.

示例:

create> DocA.name = "foo" => changelist = 1 create> DocB.name = "bar" => changelist = 2 update> DocA.name = "bob" => changelist = 3 create> DocC.name = "joe" => changelist = 4

结果:

DocA.changelist = 3 DocB.changelist = 2 DocC.changelist = 4

然后,我可以搜索在changelist:4之后进行的所有更改,并确信我没有错过任何事情.

Then I can search for any changes made after changelist:4 and be confident I did not miss anything.

任何来自mongodb专家的想法如何有效地做到这一点?

Any thoughts from the mongodb gurus on how to do that efficiently?

推荐答案

MongoDB文档列出了自动递增字段.一般来说,这是不好的做法,但这可能会满足您所寻求的功能.

The MongoDB docs have a listing for auto-incrementing fields. In general it is bad practice, but this could work for the functionality you seek.

也就是说,我还看到人们在上次更新时间使用时间戳".这可能满足您的要求.

That stated, I have also seen people use "timestamps" for the last updated time. This may satisfy your requirements.

同样,如果这是一个非常关键的功能,则您可能想看看Riak的MVCC,它似乎与您想要的最接近.

Likewise, if this is a really key feature, you may want to look at Riak's MVCC which seems closest to what you want.

更多推荐

MongoDb中的全局自动递增字段

本文发布于:2023-10-28 18:04:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1537375.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   全局   MongoDb

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!