const search = ‘5000’;
const selector = {
’$or’: [
{ ‘name’: {’$regex’: search, ‘$options’: ‘x’} },
{ ‘price’: {’$regex’: search, ‘$options’: ‘x’} },
]
};
but this only work with string column, it not work with number.
i want to search all colums and all type? how to do that ?
Yes - it also can’t take advantage of indexes. See the linked to docs for more info (@sashko - I think you meant it needs to do a full collection scan, not a full database scan?).
Also important is sanitizing input to $where. If user input is passed in there it could easily dos your mongodb. $where executes arbitrary javascript and selects all records where that javascript evaluates to true.