I am trying to perform full text search on MongoDB and Node.js using the mongoose-text-search plugin. I am following the example code from https://github.com/aheckmann/mongoose-text-search and my code is shown below. I keep getting an error stating: "Error: text search not enabled. undefined" I followed the directions from Installing plugins for mongoose - getting error, which led me to the MongoDB site: http://docs.mongodb.org/manual/tutorial/enable-text-search. However, after I enable text search by typing the command:
mongod --setParameter textSearchEnabled=true
in terminal, I start my application and encounter an additional error. It states: "MongoError: E11000 duplicate key error index: meddb.tweets.$id_1 dup key: { : null } This is error: Error: text search not enabled undefined"
If any of you have encountered this error and found a way around it , please let me know what I am missing or need to change.
var mongoose = require('mongoose');
var textSearch = require('mongoose-text-search');
var Schema = mongoose.Schema;
var twitterSchema = new Schema ({
id: {type: Number, index: {unique: true, dropDups: true}},
created_at: Date,
user: [{
id: Number,
name: String,
screen_name: String,
location: String
}],
text: String,
keywords: []
});
twitterSchema.plugin(textSearch);
twitterSchema.index({keywords: 'text' });
var Tweets = mongoose.model('Tweets', twitterSchema);
Tweets.create({text: 'flu', keywords: ['disease', 'doctor', 'shots']}, function(err){
if(err){
console.log('First error: ' + err);
}
Tweets.textSearch('shots', function(err, output){
if(err){
console.log('This is error: ' + err)
}
var inspect = require('util').inspect;
console.log(inspect(output, {depth: null}));
});
});
exports.Document = function(db) {
return db.model('Tweets');
};