Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

157
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda