Server side generated id

心不动则不痛 提交于 2019-12-13 01:42:57

问题


The docs say:

Usually, the id will be generated automatically by the database server when the object is save, meaning that you may only access the id field once a document has been saved:

>>> page = Page(title="Test Page")
>>> page.id
>>> page.save()
>>> page.id
ObjectId('123456789abcdef000000000')

But I have found that it's not true:

ipdb> 
> .../lib/python2.7/site-packages/pymongo/collection.py(386)gen()
    385                     if '_id' not in doc:
--> 386                         doc['_id'] = ObjectId()
    387 

So pymongo generates id on the client side.

How to make MongoEngine to generate the ids on server side?

来源:https://stackoverflow.com/questions/34473295/server-side-generated-id

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