I am trying to write cloud code that excludes certain values from a query. I have tried using both select()
and exclude()
to limit what values come back in a query. Here is what my code looks like
Parse.Cloud.beforeFind(Parse.User, (request) => {
return request.query.select('email');
});
For reference, here is the curl command that I am using to test my cloud code:
curl --location --request GET 'https://<parse-server>.b4a.io/parse/users' \
--header 'X-Parse-Application-Id: <app-id>' \
--header 'X-Parse-REST-API-Key: <api-key>' \
--header 'X-Parse-Session-Token: <token>'
In theory, the response to this command should look something like this:
{
results:[{'email':'[email protected]'},{'email':'[email protected]'}]
}
Instead what I get is the following(all of the user information I would normally get if I did nothing):
{
"results": [
{
"objectId": "jKXYLgeB6x",
"username": "cperryoh",
"email": "[email protected]",
"isBanned": false,
"emailVerified": true,
"createdAt": "2022-07-25T17:09:37.963Z",
"updatedAt": "2022-07-27T16:34:54.186Z",
"chunksOwned": {
"__type": "Relation",
"className": "chunk"
},
"ACL": {
"jKXYLgeB6x": {
"read": true,
"write": true
},
"*": {
"read": true
}
}
},
{
"objectId": "ykJJhvNuPh",
"username": "testUser",
"email":"[email protected]",
"isBanned": false,
"emailVerified": true,
"createdAt": "2022-07-25T19:39:02.854Z",
"updatedAt": "2022-07-27T16:20:48.083Z",
"chunksOwned": {
"__type": "Relation",
"className": "chunk"
},
"ACL": {
"*": {
"read": true
},
"ykJJhvNuPh": {
"read": true,
"write": true
}
}
}
]
}
To further add to the confusion, in the cloud-code/parse-SDK documentation, there is no reference to the beforeFind trigger. So I am not even sure what the return type of lambda/function is supposed to be. The only thing I have that is telling me I can return a query object is an example in the cloud code guide here. In one of the examples, they return the result of Parse.Query.or()
which does return an object of type Query. Am I using .select()
incorrectly or is it not meant for what I am trying to do? Thanks for the help!