猫鼬模型用户根本不会填充,可能是身份验证插件

时间:2018-08-22 20:37:54

标签: mongoose-populate

用户架构

 const mongoose = require('mongoose'),
      passportLocalMongoose = require('passport-local-mongoose');

  var users_schema = new mongoose.Schema({
    username: {type : String, required : true, min : 1, unique: true}, //
    date: String,
    email: {type : String, required : true, min : 1, unique: true}, //
    lastFirstName: {type : String, required : true},//
    mailing_address: {type : String, required : true, unique: true},//
    main_office_address: {type : String, required : true, min : 1},
    office_phoneNumber: {type : String, required : true, min : 1},
    dateOfBirth: {type : String, required : true, min : 1},//
    phoneNumber: {type : String, required : true, min : 1, unique: true},//
    if_helper: {type : Boolean, required : true, min : 1},
    hiringManager: /* {type : String, required : true}*/String,
    hiredDate: String,
    manager:{type : Boolean, required : true}
  },{timestamps:true});
  users_schema.plugin(passportLocalMongoose);
  module.exports = mongoose.model("Users", users_schema, "users");

职位地址modelSchema

  const mongoose = require('mongoose');
    var job_address_schema = new mongoose.Schema({
      location: {type: String, required: true, min:1, unique: true},
      address: {type: String, required: true, min:1, unique: true},
      job_type: String,
      job_name: String,
      registered_day: String,
      job_description: String,
      registered_user_id: {
        type: mongoose.Schema.Types.ObjectId,
        ref: "Users"
      }},{timestamps:true});
    module.exports = mongoose.model("Job_address", job_address_schema);

一切正常,但是,当我调用函数时,“ registered_user_id:user_id”未填充用户个人资料:

job_address.findOne({_id:req.params.job_id}).populate({path:"users", model:user}).exec((err, result)=>{
                if(err) throw (err);
                else {
                  console.log(JSON.stringify(result, undefined, 2));
                }
              });

我已经尝试用多种方法来解决它,但仍然没有得到解决。删除猫鼬的“ passport-local-mongoose”插件时,我注意到的唯一事情是,我的“ registered_user_id:”正在填充用户个人资料。有没有解决的办法,还是我错过了什么? 谢谢

0 个答案:

没有答案