zumzum
zumzum

Reputation: 20238

parse.com cloudcode query, how to tell parse to return only certain columns of a PFObject found in a table?

I have this function on parse cloudcode:

Parse.Cloud.define("testfunction", function(request, response) {

    var username = request.params.username
    var testObject = Parse.Object.extend('Test');
    var query = new Parse.Query(testObject);
    query.equalTo('username', username);
    // PFObject "Test" in the table has columns A,B and C
    // how do I tell the query that in the final result I send back 
    // in the response I only want filed A?

    query.find({
        success:function(results) {
            response.success(results)
        },
        error:function() {
            response.error('Could not find channels')
        }
    })
});

I am not sure how to tell the query to only return filed A and not field B and C as part of any of the PFObjects that come back from the query?

thank you

Upvotes: 2

Views: 2353

Answers (1)

Björn Kaiser
Björn Kaiser

Reputation: 9912

You can use the select method of the query to limit the fields that will be returned.

var username = request.params.username
var testObject = Parse.Object.extend('Test');
var query = new Parse.Query(testObject);
query.select('A');
query.equalTo('username', username);

It is a bit hidden in the documentation but you will find it in the Query Constraints section of the JavaScript Guide [1] (you will have to scroll down a bit there to find it).

[1] https://parse.com/docs/js_guide#queries-constraints

Upvotes: 6

Related Questions