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

121
Vistas
Add a new field in mongoDB from another collection independently?

I have two collections: profiles and contents

The profiles collection looks like this:

{
  _id: ObjectId('618ef65e5295ba3132c11111'),
  blacklist: [ObjectId('618ef65e5295ba3132c33333'), ObjectId('618ef65e5295ba3132c22222')],
  //more fields
}

The contents collection looks like this:

{
  _id: ObjectId('618ef65e5295ba3132c00000'),
  owner: ObjectId('618ef65e5295ba3132c22222'),
  //more fields
}

What I need is to get those contents where owner is not included in the blacklist. I thought about to put the blacklist field into the contents documents. I could get the profile by id separately (in another query) and set it manually in the aggregation where I get the contents, but this requires one extra connection.

So my question is: Is there a way to add my profile into each document of another collection? keep in mind that I have the profile ID.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Here is some psuedo code on how it "should" look like, First fetching the blacklists owners, then using that variable as a parameter in the pipeline.

const profileId = input;
const blackListIds = await db.getCollection('profiles').distinct('blacklist', { _id: profileId });
const aggregationResults = await db.getCollection('contents').aggregate([
    {
        $match: {
            owner: {$nin: blackListIds}
        }
    }
    ... continuation of pipeline ...
])
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