1 point

mongodb - How to find items using regex in Mongoose for partial text search


Wed Jun 10 2020 12:20:30 GMT+0000 (UTC)

Posted by @mishka #javascript #mongoose #mongodb #mean

   var Person = mongoose.model('Person', yourSchema);
   // find each person with a name contains 'Ghost'
   Person.findOne({ "name" : { $regex: /Ghost/, $options: 'i' } },
          function (err, person) {
                 if (err) return handleError(err);
                 console.log('%s %s is a %s.', person.name.first, person.name.last, person.occupation);

content_copy Copy