Javascript 如何在解析服务器的数组字段中推送JSON对象

Javascript 如何在解析服务器的数组字段中推送JSON对象,javascript,json,parse-platform,parse-server,parse-cloud-code,Javascript,Json,Parse Platform,Parse Server,Parse Cloud Code,我试图在我的集合数组字段中推送或追加json对象,但收到以下错误“错误:生成响应时出错。ParseError{code:101,message:'object not found.}code=101,message=object not found.” 我正在共享我的云代码。 解析服务器-2.3.8 节点JS-6.10.2 Mongodb-3.4 var Offer = new Parse.Query(Parse.Object.extend(GameConstants.OFFER));

我试图在我的集合数组字段中推送或追加json对象,但收到以下错误“错误:生成响应时出错。ParseError{code:101,message:'object not found.}code=101,message=object not found.”

我正在共享我的云代码。 解析服务器-2.3.8 节点JS-6.10.2 Mongodb-3.4

var Offer = new Parse.Query(Parse.Object.extend(GameConstants.OFFER));
        Offer.select("collected");
        Offer.equalTo(GameConstants.OBJECT_ID, inputData.offer_id);
        Offer.first({
            success: function (offer) {
                if (typeof offer !== 'undefined') {                    
                    var collected = offer.get(GameConstants.COLLECTED);                    
                    collected.push({user_id: inputData.user_id, date_time: new Date()});                                        
                    offer.set(GameConstants.COLLECTED, collected);//{user_id: inputData.user_id, date_time: new Date()}
                    offer.save(null, {
                        success: function (offer) {
                            var GameUser = new Parse.Query(Parse.Object.extend(GameConstants.GAME_USERS));
                            GameUser.select("coins", "collected_offer");
                            GameUser.equalTo(GameConstants.OBJECT_ID, inputData.user_id);
                            GameUser.first({
                                success: function (gameUser) {
                                    if (typeof gameUser !== 'undefined') {
                                        gameUser.increment(GameConstants.COINS, inputData.coins);
                                        gameUser.addUnique(GameConstants.COLLECTED_OFFERS, {offer_id: inputData.offer_id, offer_coins: inputData.coins, date_time: new Date()});
                                        gameUser.save(null, {
                                            success: function (gameUser) {
                                                callback(null, 1);
                                            },
                                            error: function (error) {
                                                callback(error);
                                            }
                                        });
                                    } else {
                                        callback(null, 2);
                                    }
                                },
                                error: function (error) {
                                    callback(error);
                                }
                            });
                        },
                        error: function (error) {
                            callback(error);
                        }
                    })
                } else {
                    callback(null, 2);
                }
            },
            error: function (error) {
                //Error
                callback(error);
            }
        });
请告诉我哪里出了问题。如何使用parse server在mongodb的数组字段中推送自定义json对象


谢谢。

@julien kode。我还没有一个完整的答案给你,但我有一个可能有用的建议。您正在使用老式的成功错误函数。这种异步编码风格的一个巨大问题是,错误很容易被“吃掉”。相反,您希望抓住链条的末端。这是你函数的重写。我可能错过了一点,因为我没有足够的信息来编写一个工作测试,但希望你能得到这个想法,我们可以把球向前移动到一个解决方案

const Offer = new Parse.Query(Parse.Object.extend(GameConstants.OFFER))
  .select("collected");
  .equalTo(GameConstants.OBJECT_ID, inputData.offer_id);
  .first()
  .then((offer) => {
    if (typeof offer !== 'undefined') {                    
      const collected = offer.get(GameConstants.COLLECTED); // << -- is Array.isArray(collected) === true ????    
      collected.push({ user_id: inputData.user_id, date_time: new Date() });                                        
      offer.set(GameConstants.COLLECTED, collected); 
      return offer.save(); // <<-- note how i am returning functions that result in promises -- this is the magic!
    } else {
      return callback(null, 2);
    }
  })
  .then((offer) => {
    return new Parse.Query(Parse.Object.extend(GameConstants.GAME_USERS)) // <-- whoa, we're returning the promise that results from the first() call.  cool.
      .select("coins", "collected_offer");
      .equalTo(GameConstants.OBJECT_ID, inputData.user_id);
      .first()
  })
  .then((gameUser) => {
    if (typeof gameUser !== 'undefined') {
        gameUser.increment(GameConstants.COINS, inputData.coins);
        gameUser.addUnique(GameConstants.COLLECTED_OFFERS, {offer_id: inputData.offer_id, offer_coins: inputData.coins, date_time: new Date()});
        return gameUser.save().then(() => callback(null, 1)) // a single line function with no {} will return the result of the expression....
    } else {
        return callback(null, 2);
    }
  })
  .catch(callback); <-- this is the same as .catch((error) => callback(error));
constoffer=newparse.Query(Parse.Object.extend(GameConstants.Offer))
.选择(“已收集”);
.equalTo(gamestants.OBJECT\u ID,inputData.offer\u ID);
.first()
。然后((报价)=>{
如果(报价类型!=“未定义”){
const collected=offer.get(GameConstants.collected)//