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

146
Vistas
Get document value of the field when using aggregate in mongodb

I am using two databases in my Nestjs app. Postgres and Mongodb. I am using Prisma for managing Postgres database and using Mongoose for mongodb managing. I have two entities.

Mongo Schema;

@Schema()
export class Post {
  @Prop({ type: String })
  title: string;

  @Prop({ type: Number })
  userID: number;
}

Prisma Model;

model User {
  id    Int     @default(autoincrement()) @id
  email String  @unique
  name  String?
}

There is no relationship because I use different databases. For this i want to fill user field when finding matching post.

Like this;

 async findOne(id: string) {
    return this.post.aggregate([
      { $match: { _id: new Types.ObjectId(id) } },
      {
        $project: {              
          title: 1,
          user: await this.prisma.user.findUnique({
            // how can i get userID field in doc
            where: { id: "post.userID" },
          }),
        },
      },
    ]);
  }

But i don't know how can i get userID value. Is it possible? Thanks.

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