importnGramTextSearchfrom'mongoose-plugin-ngram-text-search';
constuserSchema=newmongoose.Schema({
email:String,
name:String,
username:String,
// your other fields...
});
// function used to extract to text to indexing from a fieldconstextractUsernameFromEmail= (str='') =>str.split('@')[0];
userSchema.plugin(nGramTextSearch, {
nGramSizeMin:1,
nGramSizeMax:8,
edgeNGrams:true,
fields: [
{ name:'username' },
{ name:'name' },
{ name:'email', extractFn: extractUsernameFromEmail },
],
});
The Tidelift Subscription provides access to a continuously curated stream of human-researched and maintainer-verified data on open source packages and their licenses, releases, vulnerabilities, and development practices.