Question: I have a problem when i query using mongoose.I coding follow this [Mongoose.js: Find user by username LIKE value](https://stackoverflow.com/questions/9824010/mongoose-js-find-user-by-username-like-value). But it return blank.

This my code return blank.

```
 var promise = UserSchema.find({name: /req.params.keyword/ }).limit(5);

```

I tried this return blank seem.

`var n = john; var promise = UserSchema.find({name: /n/ }).limit(5);`

But i tried this is working

```
 var promise = UserSchema.find({name: /john/ }).limit(5);

```

Why I use variable then return blank?

Answer: 
use `$regex` in mongodb 

[how to use regex](https://docs.mongodb.com/manual/reference/operator/query/regex/)

example 

```
select * from table where abc like %v%

```

in mongo

```
 var colName="v";
 models.customer.find({ "abc": { $regex: '.*' + colName + '.*' } },
   function(err,data){
         console.log('data',data);
  });

```

**Your query look like** 

```
var name="john";
UserSchema.find({name: { $regex: '.*' + name + '.*' } }).limit(5);

```
You can use the RegExp object to make a regex with a variable, add the 'i' flag if you want the search to be case insensitive.

```
const mongoose = require('mongoose');
const User = mongoose.model('user');

const userRegex = new RegExp(userNameVariable, 'i')
return User.find({name: userRegex})

```