2

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

1 Answer 1

6

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

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

3 Comments

ok, so, that almost works. Meaning, I went in and entered the three fields of the PFObject stored in the table I wanted to get. They come back fine. No matter what I do though it seems like "objectId", "createdAt", "updatedAt" and "__type" always get returned. Does that mean I cannot filter those out from the response?
I can't prove this now, but I would assume that, as these fields are 'core fields' on Parse, they will always be returned when you query information. What you could do is just returning a new object that just has the property of field A. So you wouldn't actually return the queried object 1:1 but only take out the information you need.
is there a way to exclude a field?

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.