问题
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