使用Query解析云功能(承诺问题)

时间:2017-11-24 15:36:43

标签: javascript node.js parse-platform parse-cloud

我有一个云功能,它应该在服务器上运行一个Jar文件,然后从数据库中获取一些数据。这就是我现在所拥有的:

Parse.Cloud.define('search', function(req, res) {
  console.log(JSON.stringify(req))
  runjar(req.params.searchTerms[0]).then(resp => {
    getids(JSON.stringify(resp)).then(resp => {
      console.log("getids output = " + resp)
      res.success(resp)
    });
  });
});

const runjar = function(searchInputString) {
  const util = require('util');
  const exec = util.promisify(require('child_process').exec);
  return exec('java -jar -Xms1024m all.jar ' + searchInputString).then(resp => {
    const string = resp.stdout;
    var regex = /(\d+)=(\d+)/g;
    var matches = getMatches(string, regex, 1);
    console.log(string);
    return matches
  });
}

const getids = function(idArray) {
    var query = new Parse.Query("collection1");
    query.containedIn('identifier', idArray);
    query.limit(10);
    return query.find().then(function(results) {
        console.log(results);
        status.success(results);
        return result;
    }, function(error) {
        console.log(error);
        status.error(error)
        return Parse.Promise.error(error);
    });
}

我的方法卡在getids函数中,它不会返回任何数据!我尝试使用单独的查询,如下所示,但我得到相同的空数组。

Parse.Cloud.define("test", function(request, response) {
  var promise = new Parse.Promise();

    var Product = Parse.Object.extend("collection1");
    var query = new Parse.Query(Product);
    query.equalTo("identifier", 309255);
    query.first().then(function(result){
        if(result){
            // If result was defined, the object with this objectID was found
            promise.resolve(result);
        } else {
            console.log("Product ID: " + productId + " was not found");
            promise.resolve(null);
        }
    }, function(error){
            console.error("Error searching for Product with id: " + productId + " Error: " + error);
            promise.error(error);
    });

    return promise;
});

0 个答案:

没有答案