Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

148
Views
Joining two collection in mongoose model giving null value

I am trying to get data from two collection but always getting null value in ref column.

i tried using populate function but everytime i am getting null value in my referenced schema type.

Below is my two collections model code :

Property Model Code :

var mongoose  = require('mongoose');
var schema = mongoose.Schema;
var Users = require('./users.model');
var PropertyType = require('./property_type.model');
var RoomType = require('./room_type.model');
var Admin = require('./admin.model');
var propertySchema = new schema({
    id: {
        type : Number,
        required : true
    },
    host_id: {
        type : schema.Types.ObjectId,
        required :true,
        ref : 'Admin'
    },
    title : {
        type : String,
        required : true
    },
    property_type : {
        type : schema.Types.ObjectId,
        required : true,
        ref : 'PropertyType'
        //foregirn key
    },
    room_type : {
        type : schema.Types.ObjectId,
        required : true,
        ref : 'RoomType'
        //foregin key
    },
});

var Property = module.exports = mongoose.model('Property', 
propertySchema);

module.exports.fetchProperties = function(callback){
    Property.find({}, callback).populate('room_type');
}

Room Type model Code

var mongoose  = require('mongoose');
var schema = mongoose.Schema;
var roomTypeSchema = new schema({
    id : {
        type : Number,
        required : true
    },
    name : {
        type : String,
        required : true
    }
});
var RoomType = module.exports = mongoose.model('RoomType', roomTypeSchema);

Please help me to know where i am wrong in the above code that i am getting null value in room_type schema type.

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!