Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$regex operator called with non regular expression #556

Open
jindalrohit opened this issue Apr 27, 2018 · 9 comments
Open

$regex operator called with non regular expression #556

jindalrohit opened this issue Apr 27, 2018 · 9 comments

Comments

@jindalrohit
Copy link

I'm trying to search string using regex as below:

db.find({ consignee: { $regex: /test/ } }, function (err, docs) {
console.log(docs);
});

But it is throwing error
Error: $regex operator called with non regular expression

@JamesMGreene
Copy link
Contributor

Can you consistently reproduce this error? Seems very odd.

@Janglee123
Copy link

@jindalrohit have you figured out how to solve this issue ?

@Janglee123
Copy link

Janglee123 commented Feb 28, 2019

@JamesMGreene I can reproduce this error now. The below function is used to find a book from the database based on the title of a book with regex.

Library.searchBook = function (name) {
    query = new RegExp(name, 'i');
    console.log({query});
    db.find({ title: { $regex: query } }, (err, result) => {
        console.log({result});
        if (err){
            console.error(err);
            return;
        }
        result.forEach(row => {
            Library.loadBook(row);
        });
    });
};

The above function gives an error every time it gets executed. The function was working perfectly before, I don't know for which version. Now it is throwing error Error: $regex operator called with non regular expression. Current version is 1.8.0. Here is the screenshot of the output and you can see the code here.
screenshot from 2019-02-28 13-16-58

@zerooverture
Copy link

I have the same problem,and $where tip
$where function must return boolean ,
But I did return boolean

@lechatthecat
Copy link

Same error. No idea how to remove this error.

@avalla
Copy link

avalla commented Jan 31, 2020

I cannot find any solution to this issue

@TheDanielMoli
Copy link

TheDanielMoli commented Jul 15, 2020

Same issue here:

{ $or: [ {email: { $regex: `.*${search}.*`, $options: 'i' }}, {name: { $regex: `.*${search}.*`, $options: 'i' }} ] };

@avalla
Copy link

avalla commented Jul 15, 2020

I replaced nedb with sqlite, performance are better and migration was not so painful

@codernoder
Copy link

codernoder commented Nov 26, 2020

Use { $regex: new RegExp('test') } instead { $regex: /test/ }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants