How to set primary key with auto increment in MongoDB? [duplicate]
This question already has answers here : Closed 5 years ago . How do you implement an auto-incrementing primary ID in MongoDB? (7 answers) How to set primary key with auto increment in MongoDB ? Normally MongoDB generates ObjectID. I wanna use my own auto increment primary key like MySQL. Examples would be appreciated :) I blogged about this here: http://www.alexjamesbrown.com/blog/development/mongodb-incremental-ids/ I also started a int id generator for the C# driver: https://github.com/alexjamesbrown/MongDBIntIdGenerator However, incrementing ID's won't scale effectively. $db->execute(