Page 1 of 1

limit the fields returned from query

Posted: Mon Jul 06, 2015 3:26 am
by Dongzhi Yang7528784

Hi Support team,

In server code script, Is there anyway to limit the fields returned from a query instead of always getting the whole records.
I have been looking for it in "Server Code API" , but i can not find anything except for the "distinct" method which can allow returning 1 field by name.

I have found in mongodb documentation that it does support projection by allowing a projection document.
http://docs.mongodb.org/manual/tutori...

Thanks

Dongzhi


limit the fields returned from query

Posted: Mon Jul 06, 2015 6:38 pm
by Illya Stepanov

Hi Dongzhi -

You can use a combination of "skip" and "limit" with your query, here are details: https://devcenter.appery.io/documenta...

and below you can find example with query method: https://devcenter.appery.io/documenta...


limit the fields returned from query

Posted: Tue Jul 07, 2015 2:53 am
by Dongzhi Yang7528784

Hi Illya,

Could you provide more details? I don't see how skip or limit can help with this.

what I want is:

e.g. I have the following returned array from a standard query.
[{"id":"xxx","name":"xxx1","age":"xxx","gender":"xxx"},
{"id":"xxx","name":"xxx2","age":"xxx","gender":"xxx"}]
but i want it to return only
[{"name":"xxx1","gender":"xxx"},
{"name":"xxx2","gender":"xxx"}]
Only some of the fields are returned.

Regards

Dongzhi


limit the fields returned from query

Posted: Tue Jul 07, 2015 6:07 am
by Illya Stepanov

You can use a Projection to return only specified collection columns --https://devcenter.appery.io/documenta...


limit the fields returned from query

Posted: Tue Jul 07, 2015 6:30 am
by Dongzhi Yang7528784

Hi Illya,

Thanks. But this projection is from the client side. I wonder if we can do it from the server side with server code script.

The purpose behind is for security. And the target is to limit some fields so that client side can not see via service request. If the projection is only from client side, clients can still get all fields of the response by sending a request without projection parameter.

Regards

Dongzhi


limit the fields returned from query

Posted: Tue Jul 07, 2015 7:50 am
by Illya Stepanov

Sure, you can use it in server code as well:

preparams.proj = {'colNumber' : 1};/pre


limit the fields returned from query

Posted: Wed Jul 08, 2015 1:53 pm
by Dongzhi Yang7528784

Hi Illya,

Thanks, this is exactly what I am looking for.
I wonder why this important feature is not in your documentation. I am sure it's very useful for many developers.

Are there any params server code supports ?

Regards

Dongzhi