Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!