In querying a collection in a Mongo database with Mongoose, how can I find where a value is LIKE a query term?

I've search hard for an answer to this but haven't found anything that works. I have a NodeJS app, with the Mongoose ORM. I'm trying to query my Mongo database where a result is LIKE the query.

I have tried using a new RegExp to find the results, but it hasn't worked for me. The only time I get a result is when the query is exactly the same as the collection property's value.

Here's what I'm using right now:

    var query = "Some Query String.";    
    var q = new RegExp('^/.*'+ query +'.*/i$');

    Quote.find({author: q}, function(err, doc){
        cb(doc);
    });

If the value of an author property contains something LIKE the query (for instance: 'some. query String'), I need to return the results. Perhaps stripping case, and excluding special characters is all I can do? What is the best way to do this? My RegEx in this example is obviously not working. Thanks!

You likely want to create your RegExp as follows instead as you don't include the / chars when using new RegExp:

var q = new RegExp(query, 'i');

I don't know of a way to ignore periods in the author properties of your docs with a RegExp though. You may want to look at $text queries for more flexible searching like that.