0

I'm running into some strange behavior when using Parse.Query.find() and am hoping someone can show me my errors. My scenario is that I'm including an array field in my query and sometimes, at a random record, some of the included array elements are null. I've verified that the array elements are indeed NOT null. Additionally, if I use each() instead of find(), I don't see this problem. Also, if I reduce the # of records I read at a time (CHUNK_SIZE) from Parse's 1000 maximum to 500, things work, so I'm not sure what's going on.

Here's the code I'm using.

/**
 Iterates over a query using find(), which is very fast, compared to each().
 Works up to 10,000 records maximum.

 @param query  Parse.Query to iterate.
 @param callback  Called for each batch of records.

 @return  Promise, fulfilled when iteration is done.
 */
function findAll(query, callback) {
    var queryCount = 0;
    var startTime = new Date();
    var CHUNK_SIZE=1000;
    query.limit(CHUNK_SIZE);

    var queryFind = function() {
        query.skip(CHUNK_SIZE * queryCount);
        queryCount++;

        return query.find().then(function(rows) {
            callback(rows);

            if (rows.length == CHUNK_SIZE) {
                return queryFind();
            }
        });
    }

    return queryFind();
}

// Example of how to use findAll. 
function fetchTree() {
    var records = 0;
    var query = new Parse.Query('TreeNode');
    query.include('scores');

    return findAll(query, function(nodes) {
        nodes.forEach(function(node) {
            records++;
            node.get('scores').forEach(function(score, scoreIndex) {
                if (!score) {
                    throw "Null score at row " + node.id + "/" + records + " index " + scoreIndex;
                }
            });
        });
    }, true);
}

fetchTree();

Thanks in advance.

1 Answer 1

2

Parse limits rows returned per query to a default of 50 with a max of 1000.

This limit includes related records, so if you get 10 records that each have on average 50 pointers in their array and you include() them you are using 500/1000 max records for your query.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.