Appengine 数据存储区未更新多条记录
votergroup = db.GqlQuery("SELECT * FROM Voter WHERE lastname = :1", 'AGEE')
for voter in votergroup:
voter.email = '[email protected]'
db.put(votergroup)
上面的代码似乎没有像 appengine 文档中显示的那样更新记录。我也尝试使用查询对象但无济于事。我知道 votergroup 正在提取记录,因为我在调试时对对象进行了计数,它显示了 10 条记录。事实上,在 db.put 之前,我循环访问了 voter.email,看起来变量已经设置了。然而,更改似乎永远不会返回到数据库。
有谁知道我可能做错了什么?
votergroup = db.GqlQuery("SELECT * FROM Voter WHERE lastname = :1", 'AGEE')
for voter in votergroup:
voter.email = '[email protected]'
db.put(votergroup)
The above code doesn't seem to be updating the records as it shows in the appengine documentation. I also tried using a query object to no avail. I know votergroup is pulling records, because I did a count on the object when debugging and it showed 10 records. In fact, before the db.put, I looped through voter.email, and it seems like the variable was set. However, the change never seems to make it back to the db.
Does anyone know what I might be doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要对使用
db.Query()
创建的查询调用fetch()
以使其返回实体列表。然后,您可以调用 put(list_of_entities) 来保留它们。看起来像这样:如果您不对查询调用
fetch()
,您仍然可以迭代结果,并且将根据需要进行数据存储 RPC 来检索小批量数据。对查询调用put()
不会执行任何操作,但您仍然可以对循环内的每个实体执行操作。请注意,这会对每个实体执行一次数据存储调用,并为迭代的每个批次执行一次调用。除非您不知道将返回多少项,否则最好使用
fetch()
。您可以使用游标将提取内容分解为更大的内容大块。尽管我找不到任何证据,但我相信 fetch() 的实体数量限制为 1000 个。
You need to call
fetch()
on the query you create withdb.Query()
to have it return a list of entities. You can then callput(list_of_entities)
to persist them all. That looks like this:If you don't call
fetch()
on the query, you can still iterate over the results, and a datastore RPC will be made to retrieve small batches as they are needed. Callingput()
on the query doesn't do anything, but you can still perform actions on each entity inside the loop.Note that this does one datastore calls for each entity, plus one call for each batch being iterated over. It's much better to use
fetch()
unless you don't know how many items will be returned.You can use cursors to break fetches up into larger chunks. I believe, though I can't find any proof, that
fetch()
has a limit of 1000 entities.试试这个:
我认为没有办法使用应用程序引擎进行批量编辑。
Try this instead:
I don't think there is a way to do mass edits with the app engine.