global auto-incrementing field in MongoDb

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

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> = "foo" => changelist = 1
create> = "bar" => changelist = 2
update> = "bob" => changelist = 3
create> = "joe" => changelist = 4


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

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

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


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.

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

Need Your Help

Invalid UTF-8 JSON when sorting a Cloudant/CouchDB search

json node.js couchdb cloudant

I received this error in particular when using Cloudant with NodeJS.

How to using Gulp plugin notify with del?

javascript gulp gulp-notify

This should be easy... I am trying to create a notification that the del is done.