更新多行条件
Update Multiple Rows Conditional
有人知道使用 Parse.com REST API 根据给定条件更新多行的方法吗?
想象一个 class "Location" 有几个位置。每个项目都有一个 "status" 列,其中包含一个枚举字符串值,例如 "ok" 或 "error".
我想做一些可以在 MongoDb 中以某种方式完成的事情
db().find(query).update({status: "ok"})
文字:
"Find all locations that match my query and then update the status to
Ok".
Parse.com REST API 批处理操作文档中没有关于它的任何内容,我怀疑 Parse.com 是否支持它。
Parse.com 支持 batch operations, but obviously not if they're bound to a condition.
我不是在寻找逐项查找所有项目然后更新它们的方法,因为这需要太长时间,我们正在谈论一万个项目。
没有办法一步完成。最接近您要查找的操作是 saveAll
函数。 JS API Reference
描述如下:
saveAll( list, options )
Saves the given list of Parse.Object. If any
error is encountered, stops and calls the error handler.
用法示例:
Parse.Object.saveAll([object1, object2, ...], {
success: function(list) {
// All the objects were saved.
},
error: function(error) {
// An error occurred while saving one of the objects.
},
});
使用此操作,您仍然需要查询对象、遍历它们并更新值,然后在更新的对象列表中调用 saveAll
。
围绕 saveAll
操作存在一些混淆——特别是它使用了多少 API 请求。这不确定是因为 Parse 改变了他们对 API 请求的计费方式,而这个操作曾经是正确的不再是这样。
Per this link:
saveAll attempts to do as few API calls as possible. Usually a call to
saveAll results in only one API request. However, if any of the
objects in the set has a relation to another unsaved object, that
object will have to be saved first, resulting in more API requests.
这不再是真的。 2014 年 4 月,Parse 将其定价模型更改为 每秒请求数 指标,但同年晚些时候 Parse also 自开发人员开始利用批处理操作以来,更改了批处理 API 请求的计数方式。
Here is an excerpt of an official Parse statement on the matter:
we noticed some developers were abusing this exemption and
seriously degrading performance for the other apps on their shared
clusters. We investigated further and found that the cumulative impact
of the mismatch between predicted resources and actual demands, even
among well meaning developers, was contributing to instability in the
broader system.
We removed the exemption and intend to continue with this model going
forward. That said, we completely understand that this will require
changes for the developers that relied on the previous model.
今天使用 saveAll
操作将导致列表中每个对象有 1 个 API 请求,有效地为每个单独的对象调用 save
。
目前,无法避免必须对每个修改后的对象调用保存。希望这是 Parse 将来会考虑添加的内容。
有人知道使用 Parse.com REST API 根据给定条件更新多行的方法吗?
想象一个 class "Location" 有几个位置。每个项目都有一个 "status" 列,其中包含一个枚举字符串值,例如 "ok" 或 "error".
我想做一些可以在 MongoDb 中以某种方式完成的事情
db().find(query).update({status: "ok"})
文字:
"Find all locations that match my query and then update the status to Ok".
Parse.com REST API 批处理操作文档中没有关于它的任何内容,我怀疑 Parse.com 是否支持它。 Parse.com 支持 batch operations, but obviously not if they're bound to a condition.
我不是在寻找逐项查找所有项目然后更新它们的方法,因为这需要太长时间,我们正在谈论一万个项目。
没有办法一步完成。最接近您要查找的操作是 saveAll
函数。 JS API Reference
描述如下:
saveAll( list, options )
Saves the given list of Parse.Object. If any error is encountered, stops and calls the error handler.
用法示例:
Parse.Object.saveAll([object1, object2, ...], {
success: function(list) {
// All the objects were saved.
},
error: function(error) {
// An error occurred while saving one of the objects.
},
});
使用此操作,您仍然需要查询对象、遍历它们并更新值,然后在更新的对象列表中调用 saveAll
。
围绕 saveAll
操作存在一些混淆——特别是它使用了多少 API 请求。这不确定是因为 Parse 改变了他们对 API 请求的计费方式,而这个操作曾经是正确的不再是这样。
Per this link:
saveAll attempts to do as few API calls as possible. Usually a call to saveAll results in only one API request. However, if any of the objects in the set has a relation to another unsaved object, that object will have to be saved first, resulting in more API requests.
这不再是真的。 2014 年 4 月,Parse 将其定价模型更改为 每秒请求数 指标,但同年晚些时候 Parse also 自开发人员开始利用批处理操作以来,更改了批处理 API 请求的计数方式。
Here is an excerpt of an official Parse statement on the matter:
we noticed some developers were abusing this exemption and seriously degrading performance for the other apps on their shared clusters. We investigated further and found that the cumulative impact of the mismatch between predicted resources and actual demands, even among well meaning developers, was contributing to instability in the broader system.
We removed the exemption and intend to continue with this model going forward. That said, we completely understand that this will require changes for the developers that relied on the previous model.
今天使用 saveAll
操作将导致列表中每个对象有 1 个 API 请求,有效地为每个单独的对象调用 save
。
目前,无法避免必须对每个修改后的对象调用保存。希望这是 Parse 将来会考虑添加的内容。