i want to retrieve all posts
const blogs = await Blog.aggregate([
{
$lookup: {
from: "tags",
localField: "author",
foreignField: "_id",
as: "blog_tags"
}
},
])
this code displays the posts like this
but i want to merge what is in blog_tags and make it in parent blog(bring it to the front)
blog model:
const BlogSchema = new mongoose.Schema(
{
title: {
type: String
},
content: {
type: String
},
author: {
type: mongoose.Schema.Types.ObjectId,
ref: Tags
},
content_type: {
type: mongoose.Schema.Types.ObjectId,
ref: Tags
},
}
tag schema:
const TagSchema = new Schema({
name: {
type: String
},
type: {
type: Object,
},
color: {
type: String
},
timestamp: {
type: Date,
default: Date.now
},
});