Function Definition for Basic Field Query

First of all thanks to @Michael_Lynn for an amazing intro to MongoRealm for setting up an API at Create a Data Enabled API in MongoDB Realm in 10 Minutes or Less and Create a Data Enabled API in 10 Minutes with MongoDB Realm - YouTube . Those are really valuable resources.

I have an API configured using the sample Function. I am trying to figure out how I can pass a parameter in an API call to the function so that I can filter/query based on a specific field or fields in my database. I realize this related to the find({}) portion of the function but I am not certain how to relate that to a parameter in the API or what the syntax would be to do a Boolean search among several query parameters.

Any help would be much appreciated.

Related question - is there a library of sample functions somewhere?

1 Like

I was trying something like this but it does not seem to work

return mycollection.find({"dt_filename":payload.query.testparam}).limit(10).toArray();

Never mind - the example I posted did work - just had not correctly deployed that try

1 Like

I’m not aware of a sample realm function library - but I love the idea… let me do some digging and perhaps create a repo.

2 Likes

Thanks

Question related to my initial example

How would you change this to make the search case insensitive? When comparing with a string I know you can use /string/i but that does not seem to work in syntax when comparing it to a query variable.

How would I change the function for multiple query parameters to be avilable which are ignored if not submitted but ANDed together if multiple parameters used?