How to Use MongoDB TextSearch by Mongoose
2014/8/22 min read
bookmark this
This blog shows example code of how to use MongoDB's text search by use Mongoose. You can also find What's Mongoose Text Search at here.
How to use MongoDB text search with Mongoose
First, install following npm module.
textSearch = require('mongoose-text-search')
set up your schema
// give schema text search capabilities
yourMongooseSchema.plugin(textSearch);
// add a text index
yourMongooseSchema.index(
{
Title: 'text'
});
Following is example how to use text search.
var option = {
// list of schema property you do not want to include
project: '-DealId -DealSiteId -Title'
// casts queries based on schema
, filter: { likes: { $gt: 1000000 }}
, limit: 10
, language: 'spanish'
, lean: true
};
var keyWord = 'key word to search'
yourCollection.textSearch(keyWord , option, function (err, output)
{
}
More about Mongoose with MongoDB text search, check mongoose-text-search.
Mongodb need to be 2.4 or higher
Other References
- Blog -MongoDB Text Search Explained
- Enable Text Search
- MongoDB release note 3.0
- MongoDB release note 3.2
- $text
- Text Searching with MongoDB
Other Search Engine
Want to use other popular search engine?