2016-04-14 6 views
0

私はMongoDbを使ってデータを保存しているnodejsに既にビルドされた古いプロジェクトを持っています。 Mongodbのバージョンは2.4mongoose-text-searchが動作しません

です。問題は、コレクション上でテキスト検索を実行していますが、console.log(引数)を意味する何も返されません。それはスキーマが のvarスキーマでいます私はMongoの端末でdb.socialposts.runCommand("text", { search: "accessories",limit: 1 })を実行することができるよ、みんなに知らせるためだと

結果は非常に速くなっ
var options, search; 

options = { 
    limit: 1 
}; 

search = 'accessories'; 

console.log(search); 

SocialPost.textSearch(search, options, function(err, out) { 
console.log(arguments); 
return true; 
}); 

を印刷しない飽きません。

schema = new mongoose.Schema({ 
entity_id: { 
    type: mongoose.Schema.Types.ObjectId, 
    required: true 
}, 
social_id: { 
    type: String, 
    required: true 
}, 
type: { 
    type: String, 
    required: true 
}, 
app: { 
    type: String, 
    required: true 
}, 
date: { 
    type: Date, 
    required: true 
}, 
url: { 
    type: String, 
    required: true 
}, 
post: { 
    type: String 
}, 
title: { 
    type: String 
}, 
image: { 
    type: String 
}, 
video: { 
type: String 
}, 
hashtags: [String] 
}, { 
strict: 'throw' 
}); 

インデックスが

schema.index({ 
    type: 1, 
    social_id: 1 
}); 

schema.index({ 
    type: 1, 
    entity_id: 1, 
    date: 1 
}); 

schema.index({ 
    title: 'text', 
    post: 'text' 
}); 

答えて

-1

である私は、私はそれがステータスが接続されていないを接続してのクエリを実行していたとき、それは、マングースの接続に問題だった、それを考え出しました。だから私はそれを次のように変更し、それがうまくいった。

mongoose.connect('mongodb://localhost/test', function (err) { 
     ItemModel.textSearch('D', function (err, output) { 
     if (err) 
      console.log(err); 
     else 
      console.log(output); 
     mongoose.disconnect(); 
    }); 
    }); 
関連する問題