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

107
Vistas
How do I perform a search referenced models with mongoose?

I have up 2 models "car" and "carcheck" . Car has plate and manufacturer, model as model items and carcheck has its own items plus a reference to the car model. How is it possible to create a Search Query for carcheck model that will look also into the reference items of plate, manufacturer and model?

Searching for plate manufacturer or model straight away just returns an empty array.

const defineSearchQueryForCarCheck = (req)=>{
    return req.query.search ? {
        $or:[
            {plate: {$regex:req.query.search, $options: "i"}},
            {manufacturer: {$regex:req.query.search, $options: "i"}},
            {model: {$regex:req.query.search, $options: "i"}},
            {milage: {$regex:req.query.search, $options: "i"}}
        ],           
 
    }: {}
}

The above code is the one that returns the empty array.

I also tried car.plate, car.manufacturer and so on, or car[plate] etc. but they do not seem to be working.

the model for the carCheck is:

const mongoose = require("mongoose");

const carCheckSchema = new mongoose.Schema({
    car: {type: mongoose.ObjectId,ref:"Car",required:true},
    milage: {type:String, required:true},
    condition: {type:String, required:true},
    conditionComments: {type:String},
    carCheckedStatus: {type:Boolean, default:false},
    }, {
        timestamp : true,
});

module.exports = mongoose.model("CarCheck", carCheckSchema);

and the car model is the below code:

const mongoose = require("mongoose");

const carsSchema = new mongoose.Schema({
    plate: {type:String, required:true, unique: true},
    manufacturer: {type:String, required:true},
    model: {type:String, required:true},
    }, {
        timestamp : true,
});

module.exports = mongoose.model("Car", carsSchema);
about 4 years ago · Juan Pablo Isaza
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