2015-12-15 63 views
1

我想在我的模型做很多索引,當我在做查詢在該查詢貓鼬創建多個指標和個性化quety具體指標來電

使用特定的指標,這是我的模型

var mongoose = require('mongoose'), 
Schema = mongoose.Schema; 

var ThingSchema = new Schema({ 

     word:{ 
      type: 'ObjectId', 
      required:true 
     }, 
     frecuency:{ 
      type: String, 
      default:'enabled' 
     }, 
     document:{ 
      documentId:{ 
       type: 'ObjectId' 
      }, 
      quality:{ 
       type: Number 
      } 
     }, 
     location: { 
      type: [Number], 
      index: '2d' 
     }, 
     createdAt: { 
      type: Date, 
      default: Date.now 
     }, 
     updatedAt: { 
      type: Date, 
      default: Date.now 
     } 
    }); 

module.exports = mongoose.model('Thing', ThingSchema); 

我想有這些索引:

  • 由字索引(是一個字符串)
  • 指數位置(是geoindex)
  • 指數詞和位置

現在,當我做一個查詢我想指定要使用

回答

0

module.exports線之前其指數:

ThingSchema.index({word: 1}); 
// all other indexes you want to add... 

而當它的時間要進行查詢,請使用hint()指定要使用的索引:

Thing.find({...}).hint({word: 1});