Parse & JS: Counting objects

This entry is part 21 of 25 in the series Parse & Javascript

In SQL, we always use select count to get the number of records in a table.

For Parse, we can use the query count function.

<!doctype html>
<head>
    <title>My Parse App</title>
    <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
    <script type='text/javascript' src='http://www.parsecdn.com/js/parse-1.2.17.min.js'></script>
</head>

<body>

<div>
    <div style='display:none' class='error'>
        <h1>Movie not found</h1>
    </div>

    <div style='display:none' class='success'>
        <h1>Movie Found</h1>
    </div>
</div>

<script>
    Parse.initialize('5d3sro43zBGj8AMYqWND5bFYMzAan7f5P5euZm7M', 'hlRZZqAylA7Fmah4Kk6ma8WK7QCT4cHrxjafnnkI');
    var MoviObject = Parse.Object.extend('MoviObject');
    var moviObject = new MoviObject();

    var query = new Parse.Query(MoviObject);

    query.equalTo('releaseYear', 2013);

    query.count({
        success: function(count) {
            // The count request succeeded. Show the count
            document.write("No of movies released in the year 2013:  " + count);
        },
        error: function(error) {
            // The request failed
        }
    })
</script>

</body>
</html>
Try The Code
Series Navigation<< Parse & JS: Matching values with containedIn
Parse & JS: Relational data >>