Lee Fee
Posts: 0
Joined: Sun Mar 29, 2015 11:13 pm

How can you query a database using server code?

How can you query a database using server code (instead of a request query string approach)?

The javascript code also needs to add wildcards to the search term. For example a query of 'bread' into a food database could return 'sourbread', 'white bread', 'bread pudding', etc

The process overview is shown below:

/// 1. User searches for something ///
User enters query into a search bar (mobiletextinput)

/// 2. Map the search query to service request ///
Mapped to the body of a service request. (as opposed to a querywhere)

/// 3. server code request to get user query ///
var query_on_server = request.object().mobiletextinput;

/// 4. set up criteria from which to interrogate database ///
params.criteria = {"coloumn_in_collection_to_be_searched" : query_on_server_with_wildcards};

/// 5. server code - Interrogate database using query ///
query(dbId, collectionName[, params][, token] ...

/// 6. server returns query results to user... ///

I am struggling on point 4 with the query_on_server_with_wildcards bit. Naively I thought this would be a generic problem but can't find an answer elsewhere on the forum.

Any help would be much appreciated.

Many thanks,
Lee

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

How can you query a database using server code?

Hello,

Please look at this documentation page: https://devcenter.appery.io/documenta...

Lee Fee
Posts: 0
Joined: Sun Mar 29, 2015 11:13 pm

How can you query a database using server code?

Thanks Sergiy,

Before posting this, I had successfully used the documentation page to create the parameters (params....) for 'skip', 'limit', 'sort', and code for step 5 (above).

This all functions perfectly well and as expected. The issue is with the use of 'params.criteria' which is not well detailed in either the Appery or Mongo documentation.

Perhaps a Regular Expression could be used to add a wildcard onto the variable 'query_on_server'?

I am certain other people will encounter this problem and I would be grateful if you could share some insight as to how to use 'params.criteria' for this fairly generic application.

Kind regards,
Lee

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

How can you query a database using server code?

You have to use query object like it is described her: criteria – JSON – queries the object that was built in accordance with the mongo querying documentation.

Also you can find examples here: https://devcenter.appery.io/documenta...

Return to “Issues”