MongoDb中的全局自动递增字段 [英] global auto-incrementing field in MongoDb

查看:86
本文介绍了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中的全局自动递增字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆