Parse.com geospatial Counting request is always limited to 100

My goal is to get a count that can be used to display an estimate of the number of devices that will receive a click based on the same criteria. However, I believe I am running into an error in MongoDB that I have found workarounds, but I am looking for a similar workaround using Parse.

This link provides a description of the problem and a possible workaround: https://groups.google.com/forum/?fromgroups=#!topic/mongomapper/MfRDh2vtCFg

See also this stackoverflow: Mongo and there will always be 100 with geodata

I just can't figure out how to get the workaround to work with Parse. The descriptive documentation for the Geo Queries REST API shows an example of using $ internally, but it looks like the only valid request for $ inside is a $ box request. I tried using $ center, $ centerSphere, etc., but Parse just returned an error that was expecting the "$ box" key.

I am using Parse REST API. The request looks like this with some formatting to make it readable:

installations/?where={
    "channels": {
        "$in": ["Everyone"],
        "$nin": []
    },
    "location": {
        "$nearSphere": {
            "__type": "GeoPoint",
            "latitude": 35.4432,
            "longitude": -97.6238
        },
        "$maxDistanceInMiles": 10
    }
}
&count=1
&limit=0

      

My questions are: Is there a way to get the suggested workarounds working in Parse? Maybe something undocumented? If not using REST API, maybe .NET SDK?

+3


source to share


1 answer


I haven't found a pleasant workaround for this problem to date. I would look at this in cloud-based code where you can make multiple separate count requests recursively and then return the result without network overhead for each request.

Create your cloud function and query to run with all related criteria, then use a function like:



function recursiveCountForQuery(query, count) {
    console.log("recursiveCountForQuery now @ " + count);

    query.limit(100);
    query.skip(count);

    return query.find().then(function(values) {
        var number = values.length;
        var total = count + number;

        if (number < 100 || total >= 500) {
            return Parse.Promise.as(total);
        } else {
            return recursiveCountForQuery(query, total);
        }
    });
}

      

to run the request and wait for the promise to return a counter ( total >= 500

so it doesn't run for too long, but can be removed / changed depending on your use case).

0


source







All Articles