Dongzhi Yang7528784
Posts: 0
Joined: Mon May 11, 2015 6:28 am

limit the fields returned from query

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

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

limit the fields returned from query

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...

Dongzhi Yang7528784
Posts: 0
Joined: Mon May 11, 2015 6:28 am

limit the fields returned from query

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

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

limit the fields returned from query

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

Dongzhi Yang7528784
Posts: 0
Joined: Mon May 11, 2015 6:28 am

limit the fields returned from query

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

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

limit the fields returned from query

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

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

Dongzhi Yang7528784
Posts: 0
Joined: Mon May 11, 2015 6:28 am

limit the fields returned from query

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

Return to “Issues”