1

I am building a website, using angularJs and mongoDB with restheart, to build a database.

enter image description here

My input is written in this way,

        <th><input types="number" ng-model="GeneN" ng-change="change()"></th>
        <th><input types="number" ng-model="Des" ng-change="change()"></th>
        <th><input types="number" ng-model="Org" ng-change="change()"></th>
        <th><input types="number" ng-model="Site" ng-change="change()"></th>

My filter argument is

$scope.change = function(){
        $http.get("http://localhost:3000/pupdb/pupdb/?count&pagesize=10&filter={'uniprot_AC':{'$regex':'(?i)"+$scope.UniP+".*'},'gene_name':{'$regex':'(?i)"+$scope.GeneN+".*'},'species':{'$regex':'(?i)"+$scope.Org+".*'},'description':{'$regex':'(?i)"+$scope.Des+".*'},'site':{'$regex':'(?i)"+$scope.Site+".*'}}")

It turns out that I have to input a text or a blank space in all 5 input area before I can activate the filter and return a result. After that, I can input just in one area and left the other 4 blank, and the results showed. It seems like one input is not enough to trigger the filter.

I try to use ng-init and use one blank space and without one blank space, but it is not working at all. Only if there is one character in ng-init, it will trigger the filter.

I was thinking if an "or" argument in restheart filter will solve the problem? If so, please let me know how to write.

What should I do to over come this issue?

pill45
  • 599
  • 3
  • 8
  • 23

1 Answers1

0

Passing several values to the filter qparam will actually chain them using the AND operator.

If you want to use OR try something like (I haven't tested it):

$http.get("http://localhost:3000/pupdb/pupdb/?count&pagesize=10&filter={'$or': [{ "description" : { "$regex" : "(?i)\"+$scope.Des+\".*" }}, {  "gene_name" : { "$regex" : "(?i)\"+$scope.GeneN+\".*" }}, {  "site" : { "$regex" : "(?i)\"+$scope.Site+\".*" }}, {  "species" : { "$regex" : "(?i)\"+$scope.Org+\".*" }}, {  "uniprot_AC" : { "$regex" : "(?i)\"+$scope.UniP+\".*" }}]")

See https://docs.mongodb.org/manual/reference/operator/query/or/

Andrea Di Cesare
  • 1,125
  • 6
  • 11