Mendo
Mendo

Reputation: 319

Mongoose Mongodb

Thanks in advance. I have a mongoose schema as below:

var bookSchema = new mongoose.Schema({
  name: { type: String, index: true, default: '' },
  text: { type: String, index: true, default: '' },
  date: { type: Date, default: Date.now },
  price: { type: Number, default: 0 } });

bookSchema.index({text: 1, name: 1}, {unique: true});

My problem is when I search for any text in the field named "text" it doesn't work. Possibly a naming conflict, do I have to change the field name to something other than text...

Book.find( { $text : { $search : 'mongoose is great' } } )...

Upvotes: 0

Views: 78

Answers (2)

Mendo
Mendo

Reputation: 319

Thanks for your effort in helping.

The issue I had was a small but painful lesson. As it turns out I went into my mLabs console and noticed that the Indexes for the collection totaled more than 16! So deleted all of them and added the one I needed. It turned out great, fixing my problem.

So I am guessing that if you keep adding Indexes without deleting the prior one's you end up getting unpredictable results.

Thanks again to all that answered.

Upvotes: 0

Chen
Chen

Reputation: 9

text is a reserved word in MongoDB. Don't use this word, try with another.

Upvotes: 1

Related Questions