How to Use MongoDB TextSearch by Mongoose
2014/08/022 min read
bookmark this
Table of Contents
- How to use MongoDB text search with Mongoose
- Mongodb need to be 2.4 or higher
- Other References
- Other Search Engine
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.
mongoose-text-search
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](../../blog/post/mongodb-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?
Solr](https://blog.codecentric.de/en/2013/01/text-search-mongodb-stemming/)
- [Solr.NET](https://github.com/mausch/SolrNet)
- Elasticsearch.NET