我正試圖按照Parse的文檔/示例在後臺作業中運行查詢。我想要做的是通過數據庫中的所有User
進行查詢,並對與每個User
關聯的matchCenterItem
運行查詢。解析後臺作業不正確查詢所有用戶
當我運行此作業時,它記錄status.success
,但它不會超過console.log('about to start the matchCenterItem query');
。
query.find().then(function(results)
從來沒有運行,給我的印象是,我要麼錯誤地構造matchCenterItem
查詢,要麼通過正確的方式來查詢每個User
。爲了保持簡潔,我只發佈了相關的代碼片段,但如果需要,我會很樂意發佈後臺作業的整個代碼。
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
你是否從'function(user){}'返回任何東西?由於這是做異步工作,它需要返回一個承諾,以便'each()'知道每件作業何時完成。 –
@ChrisSainty這是一個很好的觀點。我會如何正確地做這件事? – Ghobs
@ChrisSainty如果你需要更多的上下文,這裏是完整的代碼:http://codeshare.io/bN03v – Ghobs