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

163
Vistas
How to concatenate mongodb properties in nodejs variable

I'm attempting to concatenate the mongodb query in a variable in node js depending on my condition. I'm unable to concatenate the mongodb attributes here. I've included the output I'm looking for below. I understand that the + icon only concatenates strings.

  • What i need is:
var query;
query += db.collection('collection_name');
query += query.find();
if(project == true)
{
    query +=query.project(project_parameter);
}

if(limit == true)
{
    query += query.limit();
}

// Output needed if i run the query variable
db.collection('collection_name').find({id:1}).project({_id:1}).limit(10).toArray();
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If these functions support chaining, then you can do something similar to this:


let query = db.collection('collection_name')
query = query.find()
if (project === true) {
  query = query.project(project_parameter)
}

if (limit === true) {
  query = query.limit()
}

This is because calling a function on db.colllection('collection_name') returns a modified object that you can keep calling functions on.

about 4 years ago · Juan Pablo Isaza Denunciar
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