// Model
var schema = new Schema({
name: String,
email: String,
profile: {
something: String,
somethingElse: String
}
});
schema.index({name: 'text', 'profile.something': 'text'});
//Or if you want to include all string fields in the index, use the '$**' wildcard:
schema.index({'$**': 'text'});
// This would enable you to performed a paged text search query like:
MyModel.find({$text: {$search: searchString}})
.skip(20)
.limit(10)
.exec(function(err, docs) { ... });
db.stores.find( { $text: { $search: "java coffee shop" } } )
/*
Use the $text query operator to perform text searches on
a collection with a text index.
$text will tokenize the search string using whitespace and most
punctuation as delimiters, and perform a logical OR of all such
tokens in the search string.
For example, you could use the following query to find all
stores containing any terms from the list "coffee", "shop", and "java":
*/
Model.find({
$text: {
$search: `"exact_match"`
}
})
/**
* query: The query in MQL.
* First search the text using $match
*/
{
$text:{$search:'Clara De'}
}
-------------
/**
* specifications: The fields to
* include or exclude.
*. Project results
*/
{
_id:1,
name:1,
'score':{$meta:'textScore'}
}
----------
/**
* query: The query in MQL.
* $match again
*/
{
score:{ $gte: 0.2 }
}
//if you want to include all string fields in the index, use the '$**' wildcard:
schema.index({'$**': 'text'});