gpt4 book ai didi

javascript - 解析后台作业未正确查询所有用户

转载 作者:行者123 更新时间:2023-12-02 17:10:10 25 4
gpt4 key购买 nike

我正在尝试按照 Parse 的文档/示例在后台作业中运行查询。我想要做的是查询数据库中的所有 User,并对与每个 User 关联的 matchCenterItem 运行查询。

当我运行此作业时,它会记录 status.success,但它不会经过 console.log('about to start the matchCenterItem query');

query.find().then(function(results) 永远不会运行,给我的印象是我要么错误地构造了 matchCenterItem 查询,要么没有查询以正确的方式通过每个用户。为了保持简洁,我只发布了相关的代码片段,但如果需要,我很乐意发布后台作业的整个代码。

Parse.Cloud.job("MatchCenterBackground", function(request, status) {

//Parse.Cloud.useMasterKey();

console.log('background task started');
//defines which parse class to iterate through


//Query through all users
var usersQuery = new Parse.Query(Parse.User);

//For every user, do the following:
usersQuery.each(function(user) {
//query through all their matchCenterItems
var matchCenterItem = Parse.Object.extend("matchCenterItem");
var query = new Parse.Query(matchCenterItem);

// promise and searchterm arrays to be filled
var promises = [];
var searchTerms = [];

//setting the limit of items at 10 for now
query.limit(10);

console.log('about to start the matchCenterItem query');

query.find().then(function(results) {

console.log('matchCenterItem query results:' + results);
if (results.length > 0){

//code cut off here

最佳答案

好吧,这是很多代码并且嵌套很深。

据我所知,您需要返回两个当前未返回的 promise

27: return query.find().then(function(results) {
104: return Parse.Promise.when(promises).then(function(results) {

此外,您还有两个面向底部的 Promise,它们应该与 then() 链接在一起,或者与 Parse.Promise.when 并行。无论哪种情况,都需要返回结果。

232: newMComparisonArray.save({
244: mComparisonQuery.find({

所以代码的问题仅仅与创建但没有等待的 promise 有关。每当您创建 Promise 时,您都应该考虑谁在监听 Promise 的完成,并确保 Promise 返回给监听者。

关于javascript - 解析后台作业未正确查询所有用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24895383/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com