を返しません私のノードアプリケーションと一緒にMongoose version ^4.8.1
を使用しています。私は、次のようにしている上記の文書のための3つのスキーマモデル、model.find({})、</p> <p><a href="https://i.stack.imgur.com/NvBXX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NvBXX.png" alt="enter image description here"></a></p> <p>Iを( '場所')を移入移入( '位置')私はMongoDBの上に以下の構造を有する文書を有する場所と場所
Event.js
var mongoose = require('mongoose');
var eventSchema = new mongoose.Schema({
description: {
type: String
},
end_time: {
type: Date
},
start_time: {
type: Date
},
name: {
type: String
},
place: {
type: mongoose.Schema.Types.ObjectId,
ref: 'place'
}
});
eventSchema.index({name: 'text'},{'place.location.country':"text"});
var Event = mongoose.model('events', eventSchema);
module.exports= Event;
Place.js
var mongoose = require('mongoose');
var placeSchema = new mongoose.Schema({
name: {
type: String
},
location: {
type: mongoose.Schema.Types.ObjectId,
ref: 'location'
}
});
var Place = mongoose.model('place', placeSchema);
module.exports= Place;
Location.js
を作成しましたvar mongoose = require('mongoose');
var locationSchema = new mongoose.Schema({
city: {
type: String
},
latitude: {
type: String
},
country: {
type: String
},
located_in: {
type: String
},
state: {
type: String
},
street: {
type: String
},
zip: {
type: String
},
});
var Location = mongoose.model('location', locationSchema);
module.exports= Location;
アクセス/クエリデータベースへ
共通のハンドラ、
dbHandler.jsここ
querandpoplulate : function(model,condition,options)
{
return new Promise(function(resolve, reject) {
options = options||{};
console.log("model is" + model);
model.find({}).populate('place').populate('location').exec(function(error, data) {
if (error)
console.log(error);
reject(error);
console.log(data);
resolve(data);
})
})
}
iが照会方法です、
dbHelper.querandpoplulate(mongoose.model('events'), {$text: {$search: searchString},'place.location.country': countryString},function(error,data){
callback(data);
});
質問:それは結果セットを返しません場所と場所を指定すると、nullが返されます。
はまだそれが場所を返します。これは結果である – Sajeetharan
ヌル{_id:5890b47f6166c457ffdee3d3、 END_TIME:2016-11-11T00:00:00.000Z、 名: 'エネルギアツアーエウロパ - ミラノ'、 場所: null、 start_time:2016-11-10T19:00:00.000Z、 id: '631789367000065'} – Sajeetharan
あなたのインデックス 'place.location.country ':" text "'は間違っているようですが、placeはそのスキーマのobjectIdです、place.locationは未定義です。私はこれが問題を引き起こすかどうか分からないが、他のすべてはうまく見える –