Home Ask Login Register

Developers Planet

Your answer is one click away!

DirkLX February 2016

MongoChef Query IntelliShell versus QueryBuilder show different results

The following query created AND run from Query Builder shows 10 result records. If I run the same code in IntelliShell I don't receive anything? What am I missing?

A more simple one again works.


    em: {
        $regex: '.*\Qdirk\E.*',
        $options: 'i' 

A more simplistic one like this works again. Does MongoChef have issues with $regex ...

db.user.find({em: "dirk@test.com"})


3T Software Labs February 2016

Note that you've hit upon a very special case here. The use of \Q ... \E requires that the regular expression be given in slashes and not in single quotes. That is, the query must be db.user.find({ em: { $regex: /.*\Qdirk\E.*/, $options: 'i'}}) or simply db.user.find({ em: /.*\Qdirk\E.*/i }).

Be aware that this is not a problem in MongoChef, but that it is the MongoDB shell itself that requires the slashes form to be used when \Q and \E are used in the regular expression, and MongoChef's IntelliShell is based atop the MongoDB shell.

While the Collection View and Query Builder in MongoChef will happily process either form, the query text produced by the graphical Query Builder in MongoChef has been enhanced in the upcoming 3.4.0 release to always produce the slashes form, which will give consistent results if that query is then copy and pasted into the IntelliShell or the basic MongoDB shell.

Thanks for using MongoChef!

Post Status

Asked in February 2016
Viewed 1,983 times
Voted 5
Answered 1 times


Leave an answer

Quote of the day: live life