从两个单独的模型中获取数据并将其显示在我的页面上

时间:2019-03-06 11:25:49

标签: node.js mongodb mongoose


im创建了一个搜索引擎,可以显示从两个不同模型获得的数据。 (第一个模型):

var HealthInstitution = new mongoose.Schema({
    name: String,
    address: String,
    phonenumber: String,
    institution_type: {type: mongoose.Schema.Types.ObjectId, ref: 'Institution' }, 
    search_keyword: [String],
    website: String,
    created_at: {type: Date, default: Date.now},
    updated_at: {type: Date, default: Date.now}
});
HealthInstitution.index({'$**': 'text'}); 

和第二个

var User = new mongoose.Schema({
    first_name: String,
    middle_name: String,
    last_name: String,
    email: String,
    phone_number: String,
    specialty: String,
    search_keyword: [String],
    name_of_institution: String,
    type_of_institution: {type: mongoose.Schema.Types.ObjectId, ref: 'Institution' },
    type_of_profession: {type: mongoose.Schema.Types.ObjectId, ref: 'Profession' },
    password: String,
    created_at: {type: Date, default: Date.now},
    update_at: {type: Date, default: Date.now}
});
User.index({'$**': 'text'});
因此,我创建了它的索引部分,但现在我在用controller.js编写代码时遇到了问题,该代码将使搜索引擎能够从两个模型中选择信息。谢谢。

0 个答案:

没有答案