I got to implement a simple search (or it was that to my mind), the field I'm searching for is called "paymentStatus" on an Invoice and it's basically a boolean value in a mongo db (v3.4). The search comes from angular-formly input field (angularJS 1.6), and I can see it logged quite easily , as "paymentStatus - true", and "paymentStatus-false" when I send the info to search for -
{ paymentStatus: true }
Formly field looks like this -
{
key: 'paymentStatus',
type: 'horizontal-ui-select',
className: 'tooltipLabel',
templateOptions: {
optionsAttr: 'bs-options',
ngOptions: 'option[to.valueProp] as option in to.options | filter: $select.search',
label: $filter('translate')('Payment Status'),
placeholder: $filter('translate')('Payment Status'),
valueProp: 'paymentStatus',
labelProp: 'name',
searchable: true,
tooltipClass: 'wide-tooltip',
options: [
{"paymentStatus": true, "name": 'Paid'},
{"paymentStatus": false, "name": 'Unpaid'},
]
}
},
In the controller for backend to fill up the table with data to be displayed (which works correctly), I have additional code for search filter which is like this -
if (where.paymentStatus && where.paymentStatus !== null && where.paymentStatus !== undefined) {
mongoQuery[0].$match["$and"].push({"paymentStatus": {$in: where.paymentStatus}});
}
I tried playing with $eq instead of $in and basic true false toggles instead of "where.paymentStatus" which give me half result half the time. "where" is from request.allParams().data.where. I'm a beginner with DB work/searches, especially with mongo and angular JS formly. It's legacy code that's sparsely documented. Thanks for all the help.