【问题标题】:Parse query returning no results解析查询不返回任何结果
【发布时间】:2015-09-23 09:41:30
【问题描述】:

在 Parse db 上运行 600k 行的查询。我想要的对象在那里,但它仍然没有返回任何内容。一切都工作了几个星期,然后随机停止。有任何想法吗?这是查询:

// make query on parse database to find code the person entered
                    let query: PFQuery = PFQuery(className: "code")
                    query.whereKey("code", containsString: self.codeInput.text!.uppercaseString)
                    query.findObjectsInBackgroundWithBlock {(objects: [AnyObject]?, error: NSError?) -> Void in

                    // store results
                    let results: NSArray = (array: objects!)

                    // Log the error if there is one
                    if (error != nil) {
                        self.wrongCodeAnimation()
                        print("error " + error!.localizedDescription)
                    }

                        // if there aren't any results, do wrong code animation
                    else if(results.count == 0){
                        print("nothing")
                        print(results)
                        self.wrongCodeAnimation()
                    }

                        // If no error, get array of results and validate the code, get the actual code for that object, and the valid state so we can pass them into the validate function
                    else {
                        let object: PFObject = results.objectAtIndex(0) as! PFObject
                        let code: String = object.objectForKey("code") as! String
                        let codeValid: Bool = object.objectForKey("valid") as! Bool
                        print(codeValid)
                        print(code)
                        self.validateCode(code, codeValid: codeValid, codeObject: object)
                    }

                }

【问题讨论】:

  • 我不知道 swift,但您正在将代码转换为大写。您是否检查它是否存在于数据浏览器中。您可以尝试直接在解析浏览器上运行该查询以验证
  • @virendrao 数据浏览器中确实存在,代码全部大写。我只是转换为大写,以防该人意外添加了小写字符。
  • 当月达到的解析请求数是否有限制?
  • 尝试删除您的 query.whereKey 并替换为“query.limit = 10”,以确保您有数据。
  • 30reqs / 秒,1 个作业。免费计划

标签: xcode swift parse-platform


【解决方案1】:

这么明显的变化

query.whereKey("code", containsString: self.codeInput.text!.uppercaseString)

query.whereKey("code", equalTo: self.codeInput.text!.uppercaseString)

成功了。任何人都知道为什么这会产生任何影响?

【讨论】:

  • containsString 的唯一问题是:对于大型数据集来说速度很慢。也许这就是它返回空结果的原因(因为它超过了延迟限制?)
  • 有趣。感谢您的澄清。考虑到对象(无论是否为字符串)仍然是同一类型,这仍然很奇怪。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-25
相关资源
最近更新 更多