'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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
