This packages adds a searchBuilder
static method to the Mongoose model that returns a case-insensitive, regex-powered query to drop into your find functions.
const plugin = require('mongoose-partial-search');
const mongoose = require('mongoose');
const Schema = new mongoose.Schema({
name: {
type: String,
searchable: true,
}
});
Schema.plugin(plugin);
const Model = mongoose.model('foo', Schema);
const query = Model.searchBuilder('bar');
// then, use the query however you like.