【问题标题】:Parse server cloud code getting and updating an object解析服务器云代码获取和更新对象
【发布时间】:2017-08-29 14:56:55
【问题描述】:

当用户分享帖子时,我希望能够为他们提供奖励积分。我正在像这样从 xcode 调用云函数。

PFCloud.callFunction(inBackground: "shares", withParameters: ["objectID" : "z2pU3UDFrh"])

我现在硬编码一个对象 ID 只是为了检查它是否工作。 这是我调用的云代码函数

  Parse.Cloud.define("shares", function(request, response) {

    var shareQuery = new Parse.Query("Parse.POSTS");
    shareQuery.get(request.params.objectID, {
      success: function(object) {
        console.log(object)
        object.increment("score");
        object.save();
      },
      error: function(error) { },
      useMasterKey: true
    });

  });

当我检查日志时,它会打印“未定义”并且分数保持不变

【问题讨论】:

  • 表是怎么命名的? POSTS(按照惯例,你应该使用驼峰式)?
  • 是的,它被命名为 POSTS

标签: javascript swift parse-platform parse-server parse-cloud-code


【解决方案1】:

替换var shareQuery = new Parse.Query("Parse.POSTS"); 与
var shareQuery = new Parse.Query("POSTS");

Parse.Cloud.define("shares", function(request, response) {

    var shareQuery = new Parse.Query("POSTS");
    shareQuery.get(request.params.objectID, {
      success: function(object) {
        console.log(object)
        object.increment("score");
        object.save();
      },
      error: function(error) {
        console.error(error)
      },
      useMasterKey: true
    });

  });

【讨论】:

  • 这似乎已经奏效了,但我现在在日志中收到一个错误消息,指出实际上存在对象并没有找到具有该 objectId 的对象
  • 启用 VERBOSE 模式,它可能有助于解决问题
  • stackoverflow.com/questions/25622991/… u are missing .whereEqualTo 查看链接中接受的答案
  • get( objectId, options ) 由 JS SDK 在 objectId 已知时提供。 parseplatform.org/Parse-SDK-JS/api/classes/…。不需要equalsTo
  • 再试一次。如果你得到 response=empyset 而不是 object 你应该检查 POSTS 对象上的 ACL。如果用户提交的查询没有 POSTS 权限,则查询不会返回任何内容
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-20
  • 2016-08-22
  • 1970-01-01
相关资源
最近更新 更多