这里的文档说我可以省略实体的数字ID,DataStore会自动分配一个。
但是,它没有说明如何检索自动生成的ID。一个人怎么得到它?
它在响应中可用吗?还是我必须对其他一些字段进行查询才能再次检索该实体,以便可以看到其ID?
它将在相应MutationResult
的响应中。这是一个Python片段,该片段在docs中进行了扩展:
req = datastore.CommitRequest()
req.mode = datastore.CommitRequest.NON_TRANSACTIONAL
employee = req.mutation.insert_auto_id.add()
# Request insertion with automatic ID allocation
path_element = employee.key.path_element.add()
path_element.kind = 'Employee'
# ... set properties ...
resp = self.datastore.commit(req)
auto_id_key = resp.mutation_result.insert_auto_id_key[0]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句