Skip to content

Count limitations #4088

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
manishsangwan opened this issue Aug 8, 2017 · 4 comments
Closed

Count limitations #4088

manishsangwan opened this issue Aug 8, 2017 · 4 comments

Comments

@manishsangwan
Copy link

Earlier parse docs had info about limitations of count such as rate limit and timeout issues for records more than 1000. I searched the current docs and could not find much info related to it.

Are there no issues with count query now. Any links for info on this will be really helpful.

@pungme
Copy link
Contributor

pungme commented Aug 8, 2017

You can do something like this in beforeFind
http://docs.parseplatform.org/cloudcode/guide/#beforefind-triggers

Parse.Cloud.beforeFind('MyObject', function(req) {
  let isCount = req.count; // (available on parse-server 2.4.0 or up)
  if (req.count) {
     // reject or do something else 
  }
});

@addisonElliott
Copy link
Contributor

addisonElliott commented Aug 8, 2017

I would not worry about the count limit. The warning of counting more than 1000 is a remnant of parse.com.

The docs still mention that there is a 1,000 limit and 10,000 skip limit for queries which is incorrect. I was able to retrieve about 14,000 items in a short amount of time. So, counting a large amount of items will likely not be an issue.

But, to be clear, the only bottleneck for counting items is the timeout of the request.

I created a test case that demonstrates this. If you want, you can play around with it and attempt to see what the limit will be for you. Start by setting up a Parse server.

The first script to run is addEvents.js which creates a large number of events that can be counted. Change the APP-ID and server URL to match your server. Next, alter startNum and endNum values to the number of items you would like to add. Right now it makes 14,000 objects (0 - 13,999).

You can run the script in node.js by typing the following into a command-prompt: node <PATH-TO-DIR>/addEvents.js

// addEvents.js
// In a node.js environment
var Parse = require('parse/node');

Parse.initialize("addisonElliott");
Parse.serverURL = 'http://localhost:1337/parse';

var Event = Parse.Object.extend("events");

var startNum = 0;
var endNum = 14000;

var prevEvent = addEvent(startNum);
for (var i = startNum + 1; i < endNum; ++i)
    prevEvent.then(addEvent(i));

function addEvent(rating)
{
    var event = new Event();

    event.set("date", new Date());
    event.set("rating", rating);
    event.set("location", new Parse.GeoPoint(40.0, -30.0));
    event.set("isPickup", false);

    return event.save(null, {
        success: function(event) {
            console.log("Saved event #" + rating);
        },
        error: function(event) {
            console.log("Unable to save event #" + rating);
        }
    });
}

Next, you run the script testCountLimit.js to count the number of items. This can be run from a command prompt with the following command: node <PATH-TO-DIR>/testCountLimit.js

// addEvents.js
// In a node.js environment
var Parse = require('parse/node');

Parse.initialize("addisonElliott");
Parse.serverURL = 'http://24.14.44.202:1337/parse';

var Event = Parse.Object.extend("events");

countEvents();

function countEvents()
{
    var query = new Parse.Query(Event);

    return query.count({
        success: function(count) {
            console.log("countEvents: counted " + count + " events.");
        },
        error: function(error) {
            console.log("Error getting events: " + error.code + " " + error.message);
        }
    });
}

It will output the number of items counted.

@manishsangwan
Copy link
Author

thanx @pungme @addisonElliott for clearing things.

@natanrolnik
Copy link
Contributor

Closing this issue, let us know if there are any questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants