如何在MongoDB中使用自动增量设置主键? [英] How to set primary key with auto increment in MongoDB?
本文介绍了如何在MongoDB中使用自动增量设置主键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在MongoDB中使用自动增量设置主键?
How to set primary key with auto increment in MongoDB ?
通常,MongoDB生成ObjectID.我想使用自己的自动增量主键,例如MySQL.
Normally MongoDB generates ObjectID. I wanna use my own auto increment primary key like MySQL.
示例将不胜感激:)
推荐答案
我在这里写过这篇文章:
http://www.alexjamesbrown.com/blog/development/mongodb-incremental- ids/
I blogged about this here:
http://www.alexjamesbrown.com/blog/development/mongodb-incremental-ids/
我还为C#驱动程序启动了一个int id生成器:
https://github.com/alexjamesbrown/MongDBIntIdGenerator
I also started a int id generator for the C# driver:
https://github.com/alexjamesbrown/MongDBIntIdGenerator
但是,递增ID不会有效扩展.
However, incrementing ID's won't scale effectively.
这篇关于如何在MongoDB中使用自动增量设置主键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文