How to set primary key with auto increment in MongoDB? [duplicate]

女生的网名这么多〃 提交于 2019-12-03 22:34:57

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("return db.getCollection('autoInccollection').findAndModify({
                        query: { collection: '$colle' },
                        update: { '$inc': { primaryKey: 1 } },new: true
                            })");

$colle means which collection you need to create the Auto increment key.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!