September 2017
Intermediate to advanced
450 pages
11h 24m
English
Returning a document by its title is very useful, but what if we want to do a full text search for any blog post that contains a specific word in it? For instance, what if we wanted to have a search input that a visitor could type MongoDB into and get back a list of all the blog posts that contain that keyword in the title? To support such a feature, we can simply add a text index to our model Schema's title attribute to tell MongoDB that we want it to generate an index for our text in our post titles:
var mongoose = require('mongoose');var Schema = mongoose.Schema;var postSchema = new Schema({ title: { type: String, index: 'text' }, content: String, published: { type: Date, default: Date.now }});module.exports = mongoose. ...
Read now
Unlock full access