MongoDB 2.4 text search support for mongoose
Provides MongoDB 2.4 text search support for mongoose.
// modulesvar mongoose = ;var textSearch = ;// create our schemavar gameSchema = mongoose;// give our schema text search capabilitiesgameSchema;// add a text index to the tags arraygameSchemaindex tags: 'text' ;// test it outvar Game = mongoose;Game;
The output is not limited to the found documents themselves but also the complete details of the executed command.
results property of the output is an array of objects containing the found document and its corresponding search ranking.
score is the ranking,
obj is the mongoose document.
For more information about these properties, read the MongoDB documentation.
mongoose-text-search supports passing an options object as the second argument.
project: select which fields to return (mongoose field selection syntax supported)
filter: declare an additional query matcher using
findsyntax (arguments are cast according to the schema).
limit: maximum number of documents (mongodb default is 100)
language: change the search language
lean: Boolean: if true, documents are not cast to mongoose documents (default false)
var options =project: '-created' // do not include the `created` propertyfilter: likes: $gt: 1000000 // casts queries based on schemalimit: 10language: 'spanish'lean: trueGame;
As of mongoose 3.6.0, text indexes must be added using the Schema.index() method.
As of MongoDB 2.4.0, text search is experimental/beta. As such, this functionality is not in mongoose core.