Skip to content

How to push JSON Object in Array field of parse server #3846

Closed
@zack1991

Description

@zack1991

Hi, i am trying to push or append the json object in my array field of collection but i am getting this error "error: Error generating response. ParseError { code: 101, message: 'Object not found.' } code=101, message=Object not found.". I tried add(), addUnique() and set() all these methods but get the same result.

I am sharing my cloud code.
Parse Server - 2.3.8
Nodejs - 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);
            }
        });

Please help me where i am going wrong. How can i push my custom json objects in array field of mongodb using parse server.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions