0

I have some data here:
{ _id: 1, url: "romeojuliet" }
{ _id: 2, url: "romeojuliet2" }
{ _id: 3, url: "oromeojuliet" }

This is my current code

exports.searchUrl = function(req, res) {
  var url = req.body.url;

  Content.find({ 'url': /^url/i}, function(err, doc) {
  var returnValue = doc;
  if(doc == null) {
    returnValue = {};
  }
  if (err) return next(err)
    return res.send(returnValue);  
  });
};

Expect that req.body.url is "romeojuliet"
From that code I actually want to show all the data that contains "romeojuliet%",
in that case the _id 1 and 2 will appear.

Is it possible?

Hariawan
  • 233
  • 2
  • 5
  • 14

1 Answers1

0

Make this:

exports.searchUrl = function(req, res) {
  var url = req.body.url;

  Content.find({ 'url': /^romeojuliet/i}, function(err, doc) {
  var returnValue = doc;
  if(doc == null) {
    returnValue = {};
  }
  if (err) return next(err)
    return res.send(returnValue);  
  });
};
Tunaki
  • 132,869
  • 46
  • 340
  • 423
gilmar
  • 11
  • 1